Skip to content

Commit 59b76ef

Browse files
authored
test: add more tsd test cases (#12)
run test on node >= 8
1 parent da81b18 commit 59b76ef

File tree

8 files changed

+94
-38
lines changed

8 files changed

+94
-38
lines changed

.github/workflows/nodejs.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,35 @@ on:
88
branches: [ master ]
99
pull_request:
1010
branches: [ master ]
11+
schedule:
12+
- cron: '0 2 * * *'
1113

1214
jobs:
1315
build:
14-
1516
runs-on: ${{ matrix.os }}
1617

1718
strategy:
19+
fail-fast: false
1820
matrix:
19-
node-version: [4.x, 6.x, 8.x, 10.x, 12.x]
21+
node-version: [8, 10, 12, 14, 16]
2022
os: [ubuntu-latest, windows-latest, macos-latest]
2123

2224
steps:
23-
- uses: actions/checkout@v2
25+
- name: Checkout Git Source
26+
uses: actions/checkout@v2
27+
2428
- name: Use Node.js ${{ matrix.node-version }}
2529
uses: actions/setup-node@v1
2630
with:
2731
node-version: ${{ matrix.node-version }}
28-
- run: npm i
29-
- run: npm run ci
30-
env:
31-
CI: true
32+
33+
- name: Install Dependencies
34+
run: npm i
35+
36+
- name: Continuous Integration
37+
run: npm run ci
38+
39+
- name: Code Coverage
40+
uses: codecov/codecov-action@v1
41+
with:
42+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ node_modules
1414
npm-debug.log
1515
coverage/
1616
test/fixtures/ts/**/*.js
17+
.DS_Store

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"node": ">=4.2.3"
4646
},
4747
"ci": {
48-
"version": "4, 6, 8, 10, 12",
48+
"version": "8, 10, 12, 14, 16",
4949
"type": "github",
5050
"npminstall": false
5151
},

test/fixtures/timeout-and-exit.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
console.error('timer start');
44
setInterval(() => {
5-
console.error('echo every 500ms');
6-
}, 500);
5+
console.error('echo every 600ms');
6+
}, 600);
77

88
setTimeout(() => {
99
console.error('exit');
1010
process.exit(0);
11-
}, 1100);
11+
}, 1500);

test/fixtures/timeout-stderr.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
console.error('timer start');
44
setInterval(() => {
5-
console.error('echo every 500ms');
6-
}, 500);
5+
console.error('echo every 600ms');
6+
}, 600);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as runscript from '../../../';
2+
import assert = require('assert');
3+
4+
runscript('node -v', { stdio: 'pipe' }, { timeout: 30000 })
5+
.then(result => {
6+
assert(!result.stderr);
7+
assert(!!result.stdout!.toString());
8+
console.info(result.stdout!.toString());
9+
10+
return runscript('node -h', {
11+
stdio: 'pipe',
12+
stdout: process.stdout,
13+
stderr: process.stderr,
14+
}, {});
15+
})
16+
.catch((err: runscript.StdError) => {
17+
assert(err.stdio);
18+
throw new Error('should not throw');
19+
});

test/index.d.ts.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const assert = require('assert');
5+
const runScript = require('..');
6+
7+
describe('index.d.ts.test.js', () => {
8+
before(async () => {
9+
try {
10+
const stdio = await runScript('tsc -p ./ts/tsconfig.json', {
11+
stdio: 'pipe',
12+
cwd: path.join(__dirname, 'fixtures'),
13+
debug: true,
14+
});
15+
assert(!stdio.stderr);
16+
} catch (err) {
17+
console.error('should not throw error:', err.stdio.stdout.toString());
18+
throw err;
19+
}
20+
});
21+
22+
it('should compile ts without error', async () => {
23+
const stdio = await runScript('node ./ts/check.js', {
24+
stdio: 'pipe',
25+
cwd: path.join(__dirname, 'fixtures'),
26+
});
27+
assert(!stdio.stderr);
28+
const stdout = stdio.stdout.toString();
29+
assert(stdout);
30+
assert(stdout.match(/v\d+\.\d+\.\d+/));
31+
assert(stdout.match(/Options:/));
32+
});
33+
34+
it('should tsd support ExtraOptions', async () => {
35+
const stdio = await runScript('node ./ts/checkExtraOptions.js', {
36+
stdio: 'pipe',
37+
cwd: path.join(__dirname, 'fixtures'),
38+
});
39+
assert(!stdio.stderr);
40+
const stdout = stdio.stdout.toString();
41+
assert(stdout);
42+
assert(stdout.match(/v\d+\.\d+\.\d+/));
43+
assert(stdout.match(/Options:/));
44+
});
45+
});

test/runscript.test.js

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('path');
55
const assert = require('assert');
66
const runScript = require('..');
77

8-
describe('test/runscript.test.js', () => {
8+
describe('runscript.test.js', () => {
99
it('should run `$ node -v`', () => {
1010
return runScript('node -v');
1111
});
@@ -62,20 +62,20 @@ describe('test/runscript.test.js', () => {
6262
it('should reject on timeout (stderr)', () => {
6363
return runScript(`node ${path.join(__dirname, 'fixtures/timeout-stderr.js')}`, {
6464
stdio: 'pipe',
65-
}, { timeout: 1200 })
65+
}, { timeout: 1500 })
6666
.catch(err => {
6767
console.log(err);
6868
assert(err.name === 'RunScriptTimeoutError');
69-
assert(err.stdio.stderr.toString() === 'timer start\necho every 500ms\necho every 500ms\n');
69+
assert(err.stdio.stderr.toString() === 'timer start\necho every 600ms\necho every 600ms\n');
7070
});
7171
});
7272

7373
it('should normal exit before timeout', () => {
7474
return runScript(`node ${path.join(__dirname, 'fixtures/timeout-and-exit.js')}`, {
7575
stdio: 'pipe',
76-
}, { timeout: 1300 })
76+
}, { timeout: 1800 })
7777
.then(stdio => {
78-
assert(stdio.stderr.toString() === 'timer start\necho every 500ms\necho every 500ms\nexit\n');
78+
assert(stdio.stderr.toString() === 'timer start\necho every 600ms\necho every 600ms\nexit\n');
7979
});
8080
});
8181

@@ -170,26 +170,6 @@ describe('test/runscript.test.js', () => {
170170
});
171171
});
172172

173-
it('should compile ts without error', () => {
174-
return runScript('tsc -p ./ts/tsconfig.json', {
175-
stdio: 'pipe',
176-
cwd: path.join(__dirname, 'fixtures'),
177-
}).then(stdio => {
178-
assert(!stdio.stderr);
179-
180-
return runScript('node ./ts/check.js', {
181-
stdio: 'pipe',
182-
cwd: path.join(__dirname, 'fixtures'),
183-
}).then(stdio => {
184-
assert(!stdio.stderr);
185-
const stdout = stdio.stdout.toString();
186-
assert(stdout);
187-
assert(stdout.match(/v\d+\.\d+\.\d+/));
188-
assert(stdout.match(/Options:/));
189-
});
190-
});
191-
});
192-
193173
if (process.platform === 'win32') {
194174
it('should run relative path .\\node_modules\\.bin\\autod', () => {
195175
return runScript('.\\node_modules\\.bin\\autod -V', {

0 commit comments

Comments
 (0)