Skip to content

Commit 6877a2d

Browse files
authored
test: add test for optimized output (#373)
1 parent 2cfab05 commit 6877a2d

File tree

7 files changed

+81
-0
lines changed

7 files changed

+81
-0
lines changed

.github/workflows/ci.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,12 @@ jobs:
8080
node-version: 14
8181
- run: npm install
8282
- run: npm run test:typescript
83+
optimize:
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v2
87+
- uses: actions/setup-node@v1
88+
with:
89+
node-version: 14
90+
- run: cd test/tscc && npm install && npx @tscc/tscc
91+
- run: cd test/tscc && node out.js

test/tscc/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.js

test/tscc/lib

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../lib

test/tscc/optimized.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { YargsParser } from './lib/yargs-parser'
2+
3+
const parser = new YargsParser({
4+
cwd: () => { return '' },
5+
format: (str, arg) => { return str.replace('%s', arg) },
6+
normalize: (str) => { return str },
7+
resolve: (str) => { return str },
8+
require: () => {
9+
throw Error('loading config from files not currently supported in browser')
10+
},
11+
env: () => {}
12+
})
13+
14+
// Workaround the need for proper nodejs typings and externs
15+
// eslint-disable-next-line no-eval
16+
const anyDeepEqual = eval('require("assert").strict.deepEqual') as any
17+
function deepEqual<T> (actual: T, expected: T, message?: string): void {
18+
anyDeepEqual(actual, expected, message)
19+
}
20+
21+
// Quoted properties aren't allowed in these lint settings.
22+
const FLAG_X = 'x'
23+
24+
function runTests () {
25+
deepEqual(parser.parse([]).argv, { _: [] }, 'empty argv')
26+
deepEqual(
27+
parser.parse([`--${FLAG_X}=42`]).argv,
28+
{ _: [], [FLAG_X]: 42 },
29+
'guessed numeric value')
30+
deepEqual(
31+
parser.parse([`--${FLAG_X}=str`]).argv,
32+
{ _: [], [FLAG_X]: 'str' },
33+
'guessed string value')
34+
deepEqual(
35+
parser.parse([`--no-${FLAG_X}`]).argv,
36+
{ _: [], [FLAG_X]: false },
37+
'guessed boolean negation')
38+
39+
// Default values for types:
40+
deepEqual(
41+
parser.parse([`--${FLAG_X}`]).argv,
42+
{ _: [], [FLAG_X]: true },
43+
'guessed boolean default true')
44+
45+
console.log('ok')
46+
}
47+
runTests()

test/tscc/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "optimized-test",
3+
"version": "0.0.0",
4+
"dependencies": {
5+
"@tscc/tscc": "^0.6.4",
6+
"@types/node": "^10.0.3"
7+
}
8+
}

test/tscc/tscc.spec.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"modules": {
3+
"out": "optimized.ts"
4+
}
5+
}

test/tscc/tsconfig.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2017",
4+
"moduleResolution": "node"
5+
},
6+
"include": [
7+
"./*.ts",
8+
"./lib/**/*.ts"
9+
]
10+
}

0 commit comments

Comments
 (0)