Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
cibernox committed Jun 10, 2022
1 parent 4d52e5f commit 1c7b6fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sveltekit-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function svelteIntlPrecompile(localesRoot, prefixOrOptions) {
availableLocales.push(locale);

code.push(
` register(${JSON.stringify(locale)}, () => import(${
` register(${JSON.stringify(locale)}, () => import(${
JSON.stringify(`${prefix}/${locale}`)
}))`,
)
Expand Down
20 changes: 15 additions & 5 deletions tests/sveltekit-plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { describe, it, expect, vi } from 'vitest'
import { beforeEach, describe, it, expect, vi } from 'vitest'
import svelteIntlPrecompile from '../sveltekit-plugin';

vi.mock('path', () => ({
resolve(path) {
return 'fakeroot/' + path;
},
extname(filename) {
return filename.split('.')[1];
}
return '.' + filename.split('.')[1];
},
basename(filename) {
return filename.split('.')[0];
},
}));

vi.mock('fs/promises', () => ({
Expand All @@ -17,14 +20,21 @@ vi.mock('fs/promises', () => ({
}));

describe('imports', () => {
it('$locales returns a module with all the available locales', async () => {
// beforeEach(() => {

// });

it('$locales returns a module that is aware of all the available locales', async () => {
const plugin = svelteIntlPrecompile('locales');
const content = await plugin.load('$locales');
expect(content).toBe(singleLineString`
import { register } from 'svelte-intl-precompile'
export function registerAll() {
register("en-US", () => import("$locales/en-US"))
register("en", () => import("$locales/en"))
register("es", () => import("$locales/es"))
}
export const availableLocales = []`)
export const availableLocales = ["en","es","en-US"]`)
});
});

Expand Down

0 comments on commit 1c7b6fc

Please sign in to comment.