Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,23 @@ on:
- next

jobs:
prepare-yarn-cache:
name: Prepare yarn cache
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: 14.x
cache: yarn

- name: Validate cache
run: yarn

lint:
needs: prepare-yarn-cache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -23,3 +39,45 @@ jobs:
run: yarn
- name: run ESLint
run: yarn lint

test-node:
name: Test on Node.js v${{ matrix.node-version }}
needs: prepare-yarn-cache
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x, 16.x]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- name:
install
run: yarn
- name: run tests
run: yarn test

test-os:
name: Test on ${{ matrix.os }} using Node.js LTS
needs: prepare-yarn-cache
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14.x
cache: yarn
- name: install
run: yarn
- name: run tests
run: yarn test
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
node_modules/*
.idea/*
.vscode/*
node_modules
.DS_Store
*.log

4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
e2e/
.*
*.log
*.config.js
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
};
7 changes: 7 additions & 0 deletions e2e/__fixtures__/docblock/concat.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable no-unused-vars */
declare const concat: {
(a: string, b: string): string;
(a: number, b: number): number;
};

export default concat;
1 change: 1 addition & 0 deletions e2e/__fixtures__/docblock/concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (a, b) => a + b;
9 changes: 9 additions & 0 deletions e2e/__fixtures__/docblock/concat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @type ./concat.d.ts
*/

import { expectType } from 'mlh-tsd';
import concat from './concat';

expectType<string>(concat('pre', 'fix'));
expectType<number>(concat(1, 2));
6 changes: 6 additions & 0 deletions e2e/__fixtures__/docblock/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"jest": {
"runner": "../../../src/",
"testMatch": ["**/*.test.ts"]
}
}
7 changes: 7 additions & 0 deletions e2e/__fixtures__/failing/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable no-unused-vars */
declare const concat: {
(a: string, b: string): string;
(a: number, b: number): number;
};

export default concat;
5 changes: 5 additions & 0 deletions e2e/__fixtures__/failing/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expectType } from 'mlh-tsd';
import concat from '.';

expectType<string>(concat('pre', 'fix'));
expectType<string>(concat(1, 2));
6 changes: 6 additions & 0 deletions e2e/__fixtures__/failing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"jest": {
"runner": "../../../src/",
"testMatch": ["**/*.test.ts"]
}
}
7 changes: 7 additions & 0 deletions e2e/__fixtures__/passing/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable no-unused-vars */
declare const concat: {
(a: string, b: string): string;
(a: number, b: number): number;
};

export default concat;
5 changes: 5 additions & 0 deletions e2e/__fixtures__/passing/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expectType } from 'mlh-tsd';
import concat from '.';

expectType<string>(concat('pre', 'fix'));
expectType<number>(concat(1, 2));
6 changes: 6 additions & 0 deletions e2e/__fixtures__/passing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"jest": {
"runner": "../../../src/",
"testMatch": ["**/*.test.ts"]
}
}
7 changes: 7 additions & 0 deletions e2e/__fixtures__/pkg-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"types": "./types.d.ts",
"jest": {
"runner": "../../../src/",
"testMatch": ["**/*.test.ts"]
}
}
7 changes: 7 additions & 0 deletions e2e/__fixtures__/pkg-types/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable no-unused-vars */
declare const concat: {
(a: string, b: string): string;
(a: number, b: number): number;
};

export default concat;
5 changes: 5 additions & 0 deletions e2e/__fixtures__/pkg-types/types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expectType } from 'mlh-tsd';
import concat from '.';

expectType<string>(concat('pre', 'fix'));
expectType<number>(concat(1, 2));
12 changes: 12 additions & 0 deletions e2e/__snapshots__/docblock.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`reads \`@type\` comment in docblock 1`] = `
"PASS e2e/__fixtures__/docblock/concat.test.ts
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time:
Ran all test suites.
"
`;
13 changes: 13 additions & 0 deletions e2e/__snapshots__/failing.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`works with failing test 1`] = `
"FAIL e2e/__fixtures__/failing/index.test.ts
e2e/__fixtures__/failing/index.test.ts:5:19 - error - Argument of type 'number' is not assignable to parameter of type 'string'.
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time:
Ran all test suites.
"
`;
12 changes: 12 additions & 0 deletions e2e/__snapshots__/passing.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`works with passing test 1`] = `
"PASS e2e/__fixtures__/passing/index.test.ts
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time:
Ran all test suites.
"
`;
12 changes: 12 additions & 0 deletions e2e/__snapshots__/pkg-types.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`reads \`types\` property in package.json 1`] = `
"PASS e2e/__fixtures__/pkg-types/types.test.ts
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time:
Ran all test suites.
"
`;
6 changes: 6 additions & 0 deletions e2e/docblock.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, test } from '@jest/globals';
import runJest from './runJest';

test('reads `@type` comment in docblock', async () => {
expect(await runJest('docblock')).toMatchSnapshot();
});
6 changes: 6 additions & 0 deletions e2e/failing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, test } from '@jest/globals';
import runJest from './runJest';

test('works with failing test', async () => {
expect(await runJest('failing')).toMatchSnapshot();
});
6 changes: 6 additions & 0 deletions e2e/passing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, test } from '@jest/globals';
import runJest from './runJest';

test('works with passing test', async () => {
expect(await runJest('passing')).toMatchSnapshot();
});
6 changes: 6 additions & 0 deletions e2e/pkg-types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, test } from '@jest/globals';
import runJest from './runJest';

test('reads `types` property in package.json', async () => {
expect(await runJest('pkg-types')).toMatchSnapshot();
});
35 changes: 35 additions & 0 deletions e2e/runJest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import path from 'path';
import execa from 'execa';

const rootDir = path.join(__dirname, '..');

const normalize = (output: string) =>
output
.replace(/\(?\d*\.?\d+ ?m?s\b\)?/g, '')
.replace(/, estimated/g, '')
.replace(new RegExp(rootDir, 'g'), '/mocked-path-to-jest-runner-tsd')
.replace(/.*at .*\\n/g, 'mocked-stack-trace')
.replace(/(mocked-stack-trace)+/, ' at mocked-stack-trace')
.replace(new RegExp('\u00D7', 'g'), '\u2715')
.replace(new RegExp('\u221A', 'g'), '\u2713')
.replace(/\s+\n/g, '\n');

const runJest = async (project: string, options = []) => {
const { stdout, stderr } = await execa(
'jest',
[
'--useStderr',
'--no-watchman',
'--no-cache',
'--projects',
path.join(__dirname, '__fixtures__', project),
].concat(options),
{
env: { FORCE_COLOR: '0' },
reject: false,
}
);
return `${normalize(stderr)}\n${normalize(stdout)}`;
};

export default runJest;
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
projects: [
{
displayName: 'e2e',
testMatch: ['<rootDir>/e2e/*.test.ts'],
},
],
testTimeout: 20000,
};
18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@
"Saurabh Agarwala <[email protected]>"
],
"scripts": {
"lint": "eslint ."
"lint": "eslint .",
"test": "jest"
},
"dependencies": {
"create-jest-runner": "^0.6.0",
"jest-docblock": "^26.0.0",
"create-jest-runner": "^0.9.0",
"graceful-fs": "^4.2.8",
"jest-docblock": "^27.0.6",
"mlh-tsd": "^0.14.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"@babel/core": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"babel-jest": "^27.2.5",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1",
"execa": "^5.1.1",
"jest": "^27.2.5",
"prettier": "^2.4.1",
"typescript": "^4.4.4"
},
Expand Down
Loading