Skip to content

Commit

Permalink
Refine test checks
Browse files Browse the repository at this point in the history
  • Loading branch information
cibernox committed Jun 10, 2022
1 parent 76115ed commit 4d52e5f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Debug Current Test File",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}"],
"smartStep": true,
"console": "integratedTerminal"
}
]
}
42 changes: 36 additions & 6 deletions tests/sveltekit-plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
import { describe, it, expect } from 'vitest'
import { describe, it, expect, vi } from 'vitest'
import svelteIntlPrecompile from '../sveltekit-plugin';

describe('suite', () => {
it('serial test', async () => {
expect(svelteIntlPrecompile).toBeTruthy();
})
});
vi.mock('path', () => ({
resolve(path) {
return 'fakeroot/' + path;
},
extname(filename) {
return filename.split('.')[1];
}
}));

vi.mock('fs/promises', () => ({
readdir() {
return Promise.resolve().then(() => ['en-US.json', 'en.json', 'es.json'])
},
}));

describe('imports', () => {
it('$locales returns a module with 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() {
}
export const availableLocales = []`)
});
});

function singleLineString([str]: TemplateStringsArray) {
let lines: string[] = str.split('\n');
if (lines[0] === '') {
lines = lines.splice(1);
}
let firstLineSpaces = lines[0].search(/\S|$/);
return lines.map(l => l.substring(firstLineSpaces)).join('\n');
}

0 comments on commit 4d52e5f

Please sign in to comment.