-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |