Skip to content

Commit e08ec19

Browse files
committed
Add TypeScript
1 parent 805e06e commit e08ec19

10 files changed

+54
-15
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
'use strict';
33

4-
const yargs = require('yargs/yargs');
4+
const yargs = require('yargs');
55
const { hideBin } = require('yargs/helpers');
66
const { mochify } = require('@mochify/mochify');
77

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
},
99
"main": "index.js",
1010
"scripts": {
11+
"lint": "eslint .",
1112
"test": "echo \"No unit tests yet\"",
1213
"test:integration": "mocha --timeout 10000 -R spec '**/*.integration.js'",
13-
"preversion": "npm run test && npm run test:integration",
14+
"prettier:check": "prettier --check '**/*.{js,json,md}'",
15+
"build": "tsc --project tsconfig.pack.json",
16+
"clean": "rimraf --glob '!(node_modules)/**/*.d.ts' '*.d.ts'",
17+
"prepack": "npm run build",
18+
"postpack": "npm run clean",
19+
"preversion": "npm run lint && npm run prettier:check && tsc && npm test && npm run test:integration",
1420
"version": "changes --commits --footer --workspace",
1521
"postversion": "npm publish"
1622
},
@@ -41,6 +47,7 @@
4147
},
4248
"files": [
4349
"**/*.js",
50+
"**/*.d.ts",
4451
"!**/*.test.js",
4552
"!test/**",
4653
"!.*"

test/fixture/client-leak.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
describe('test', () => {
55
it('does not leak client functions into global scope', () => {
6+
// @ts-ignore
67
if (typeof MochifyReporter !== 'undefined') {
78
throw new Error('MochifyReporter leaked');
89
}

test/fixture/custom.config.yaml

-3
This file was deleted.

test/jsdom.integration.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const path = require('path');
55
const { assert } = require('@sinonjs/referee-sinon');
66
const execa = require('execa');
77

8+
/**
9+
* @typedef {import('execa').ExecaError} ExecaError
10+
*/
11+
812
describe('jsdom', () => {
913
async function run(file, ...extra_args) {
1014
try {
@@ -17,7 +21,7 @@ describe('jsdom', () => {
1721
}
1822
);
1923
} catch (error) {
20-
return error;
24+
return /** @type {ExecaError} */ (error);
2125
}
2226
}
2327

@@ -39,10 +43,10 @@ describe('jsdom', () => {
3943
const fixture = fs.createReadStream(
4044
path.resolve(__dirname, './fixture/passes.js')
4145
);
42-
fixture.pipe(cp.stdin);
46+
fixture.pipe(/** @type {Object} */ (cp).stdin);
4347
result = await cp;
4448
} catch (err) {
45-
result = err;
49+
result = /** @type {ExecaError} */ (err);
4650
}
4751

4852
assert.isFalse(result.failed);

test/playwright.integration.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const path = require('path');
55
const { assert } = require('@sinonjs/referee-sinon');
66
const execa = require('execa');
77

8+
/**
9+
* @typedef {import('execa').ExecaError} ExecaError
10+
*/
11+
812
describe('playwright', () => {
913
async function run(file, ...extra_args) {
1014
try {
@@ -24,7 +28,7 @@ describe('playwright', () => {
2428
}
2529
);
2630
} catch (error) {
27-
return error;
31+
return /** @type {ExecaError} */ (error);
2832
}
2933
}
3034

@@ -50,10 +54,10 @@ describe('playwright', () => {
5054
const fixture = fs.createReadStream(
5155
path.resolve(__dirname, './fixture/passes.js')
5256
);
53-
fixture.pipe(cp.stdin);
57+
fixture.pipe(/** @type {Object} */ (cp).stdin);
5458
result = await cp;
5559
} catch (err) {
56-
result = err;
60+
result = /** @type {ExecaError} */ (err);
5761
}
5862

5963
assert.isFalse(result.failed);

test/puppeteer.integration.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const path = require('path');
55
const { assert } = require('@sinonjs/referee-sinon');
66
const execa = require('execa');
77

8+
/**
9+
* @typedef {import('execa').ExecaError} ExecaError
10+
*/
11+
812
describe('puppeteer', () => {
913
async function run(file, ...extra_args) {
1014
try {
@@ -17,7 +21,7 @@ describe('puppeteer', () => {
1721
}
1822
);
1923
} catch (error) {
20-
return error;
24+
return /** @type {ExecaError} */ (error);
2125
}
2226
}
2327

@@ -39,10 +43,11 @@ describe('puppeteer', () => {
3943
const fixture = fs.createReadStream(
4044
path.resolve(__dirname, './fixture/passes.js')
4145
);
46+
// @ts-ignore
4247
fixture.pipe(cp.stdin);
4348
result = await cp;
4449
} catch (err) {
45-
result = err;
50+
result = /** @type {ExecaError} */ (err);
4651
}
4752

4853
assert.isFalse(result.failed);

test/webdriver.integration.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const path = require('path');
66
const { assert } = require('@sinonjs/referee-sinon');
77
const execa = require('execa');
88

9+
/**
10+
* @typedef {import('execa').ExecaError} ExecaError
11+
*/
12+
913
describe('webdriver', () => {
1014
async function run(file, ...extra_args) {
1115
try {
@@ -18,7 +22,7 @@ describe('webdriver', () => {
1822
}
1923
);
2024
} catch (error) {
21-
return error;
25+
return /** @type {ExecaError} */ (error);
2226
}
2327
}
2428

@@ -47,10 +51,11 @@ describe('webdriver', () => {
4751
const fixture = fs.createReadStream(
4852
path.resolve(__dirname, './fixture/passes.js')
4953
);
54+
// @ts-ignore
5055
fixture.pipe(cp.stdin);
5156
result = await cp;
5257
} catch (err) {
53-
result = err;
58+
result = /** @type {ExecaError} */ (err);
5459
}
5560

5661
assert.isFalse(result.failed);

tsconfig.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "@studio/tsconfig",
3+
"include": ["**/*.js"],
4+
"exclude": ["node_modules"]
5+
}

tsconfig.pack.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "@studio/tsconfig",
3+
"compilerOptions": {
4+
"types": ["node"],
5+
"declaration": true,
6+
"noEmit": false,
7+
"emitDeclarationOnly": true
8+
},
9+
"include": ["**/*.js"],
10+
"exclude": ["node_modules", "**/*.test.js", "test/**"]
11+
}

0 commit comments

Comments
 (0)