File size: 1,267 Bytes
9853b20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Lightweight test runner (Node) - uses ts-node and module-alias to load TS modules with path aliases
require('module-alias/register')
require('ts-node').register({ transpileOnly: true })
const path = require('path')
const fs = require('fs')
const tsconfig = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), 'tsconfig.json'), 'utf8'))
const baseUrl = tsconfig.compilerOptions && tsconfig.compilerOptions.baseUrl ? path.resolve(process.cwd(), tsconfig.compilerOptions.baseUrl) : path.resolve(process.cwd(), 'src')
const paths = tsconfig.compilerOptions && tsconfig.compilerOptions.paths ? tsconfig.compilerOptions.paths : { '*': ['./src/*'] }
try { require('tsconfig-paths').register({ baseUrl, paths }) } catch(e) { /* best-effort */ }
const assert = require('assert')
const codes = require('lib/codes')

(async () => {
  try {
    console.log('Running runtime tests (JS runner)')
    const c = codes.generateCode()
    console.log('Generated code:', c)
    assert.strictEqual(typeof c, 'string')
    assert.strictEqual(c.length, 5)
    assert.strictEqual(codes.validateCodeFormat(c), true)
    console.log('All tests passed')
    process.exit(0)
  } catch (err) {
    console.error('Tests failed', err)
    process.exit(1)
  }
})()