Skip to content

Commit

Permalink
test: add test for optimized output (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrems committed Jun 20, 2021
1 parent 2cfab05 commit 6877a2d
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Expand Up @@ -80,3 +80,12 @@ jobs:
node-version: 14
- run: npm install
- run: npm run test:typescript
optimize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: cd test/tscc && npm install && npx @tscc/tscc
- run: cd test/tscc && node out.js
1 change: 1 addition & 0 deletions test/tscc/.gitignore
@@ -0,0 +1 @@
*.js
1 change: 1 addition & 0 deletions test/tscc/lib
47 changes: 47 additions & 0 deletions test/tscc/optimized.ts
@@ -0,0 +1,47 @@
import { YargsParser } from './lib/yargs-parser'

const parser = new YargsParser({
cwd: () => { return '' },
format: (str, arg) => { return str.replace('%s', arg) },
normalize: (str) => { return str },
resolve: (str) => { return str },
require: () => {
throw Error('loading config from files not currently supported in browser')
},
env: () => {}
})

// Workaround the need for proper nodejs typings and externs
// eslint-disable-next-line no-eval
const anyDeepEqual = eval('require("assert").strict.deepEqual') as any
function deepEqual<T> (actual: T, expected: T, message?: string): void {
anyDeepEqual(actual, expected, message)
}

// Quoted properties aren't allowed in these lint settings.
const FLAG_X = 'x'

function runTests () {
deepEqual(parser.parse([]).argv, { _: [] }, 'empty argv')
deepEqual(
parser.parse([`--${FLAG_X}=42`]).argv,
{ _: [], [FLAG_X]: 42 },
'guessed numeric value')
deepEqual(
parser.parse([`--${FLAG_X}=str`]).argv,
{ _: [], [FLAG_X]: 'str' },
'guessed string value')
deepEqual(
parser.parse([`--no-${FLAG_X}`]).argv,
{ _: [], [FLAG_X]: false },
'guessed boolean negation')

// Default values for types:
deepEqual(
parser.parse([`--${FLAG_X}`]).argv,
{ _: [], [FLAG_X]: true },
'guessed boolean default true')

console.log('ok')
}
runTests()
8 changes: 8 additions & 0 deletions test/tscc/package.json
@@ -0,0 +1,8 @@
{
"name": "optimized-test",
"version": "0.0.0",
"dependencies": {
"@tscc/tscc": "^0.6.4",
"@types/node": "^10.0.3"
}
}
5 changes: 5 additions & 0 deletions test/tscc/tscc.spec.json
@@ -0,0 +1,5 @@
{
"modules": {
"out": "optimized.ts"
}
}
10 changes: 10 additions & 0 deletions test/tscc/tsconfig.json
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2017",
"moduleResolution": "node"
},
"include": [
"./*.ts",
"./lib/**/*.ts"
]
}

0 comments on commit 6877a2d

Please sign in to comment.