Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 36a0a78

Browse files
Craig DoremusCraig Doremus
authored andcommitted
test: Added tests for module.ts
1 parent 0210b38 commit 36a0a78

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

framework/core/module_test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
import { assertEquals, assertThrows } from 'https://deno.land/[email protected]/testing/asserts.ts'
3+
import { trimModuleExt, toPagePath, importModule } from './module.ts'
4+
5+
// Augment the window object
6+
interface MockWindow extends Window {
7+
__ALEPH: { import: (src: string, refetch?: boolean) => string | undefined }
8+
}
9+
declare let window: MockWindow
10+
11+
Deno.test('module toPagePath', () => {
12+
assertEquals(toPagePath('/pages/bar.ts'), '/bar')
13+
assertEquals(toPagePath('/foobar/index.ts'), '/foobar')
14+
15+
assertEquals(toPagePath(''), '/')
16+
17+
assertThrows(() => toPagePath({} as string))
18+
})
19+
20+
Deno.test('module trimModuleExt', () => {
21+
assertEquals(trimModuleExt('foobar.ts'), 'foobar')
22+
23+
assertEquals(trimModuleExt('baz.zip'), 'baz.zip')
24+
25+
assertEquals(trimModuleExt('barbaz.jsx.ts'), 'barbaz.jsx')
26+
27+
assertEquals(trimModuleExt('/index.ts'), '/index')
28+
29+
assertThrows(() => trimModuleExt({} as string))
30+
31+
assertEquals(trimModuleExt('😀'), '😀')
32+
33+
})
34+
35+
Deno.test('module importModule', async () => {
36+
// mock __ALEPH.import
37+
function foo(str: string, refetch: boolean = false) {
38+
if (refetch) {
39+
return 'refetching...'
40+
}
41+
return str
42+
}
43+
window.__ALEPH = {
44+
import: foo
45+
}
46+
47+
const return1 = await importModule('/foo/bar', 'baz.ts')
48+
assertEquals(return1, 'baz.ts')
49+
50+
const return2 = await importModule('/foo/bar', 'baz.ts', true)
51+
assertEquals(return2, 'refetching...')
52+
})

0 commit comments

Comments
 (0)