Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for optimized output #373

Merged
merged 4 commits into from
Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.js
1 change: 1 addition & 0 deletions test/tscc/lib
47 changes: 47 additions & 0 deletions test/tscc/optimized.ts
Original file line number Diff line number Diff line change
@@ -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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion fails before #371.

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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"modules": {
"out": "optimized.ts"
}
}
10 changes: 10 additions & 0 deletions test/tscc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2017",
"moduleResolution": "node"
},
"include": [
"./*.ts",
"./lib/**/*.ts"
]
}