forked from timreichen/importmap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-tests.ts
46 lines (41 loc) · 1.11 KB
/
run-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { readdirSync } from 'fs'
import { types } from 'util'
import { resolve } from 'path'
const regex = /(test|spec).(m|c)?(j)sx?$/m
const arg = process.argv.slice(2)[0]
const dir = resolve(process.cwd(), arg ? arg : '')
console.log('Running tests in', dir)
const files = readdirSync(dir).filter((file) => regex.test(file))
const tests: {name: string; fn: () => Promise<any>}[] = []
globalThis.Deno = {}
globalThis.Deno.test = function test({name, fn}: {name: string, fn: () => Promise<any>}) {
tests.push({ name, fn })
}
async function run() {
await Promise.all(files.map((file) => import('file://' + dir + '/' + file))).catch((e) =>
console.log(e)
)
tests.forEach((t) => {
if (types.isAsyncFunction(t.fn)) {
t.fn()
.then(() => console.log('✅', t.name))
.catch((e) => {
console.log('❌', t.name)
console.log(e.stack)
})
} else {
try {
t.fn()
console.log('✅', t.name)
} catch (e) {
console.log('❌', t.name)
console.log(e.stack)
}
}
})
}
try {
run()
} catch (error) {
console.error(error);
}