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

fix: use tsd instead of forked mlh-tsd #25

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion e2e/__fixtures__/docblock/concat.test.ts
Expand Up @@ -2,7 +2,7 @@
* @type concat.d.ts
*/

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

expectType<string>(concat('pre', 'fix'));
Expand Down
2 changes: 1 addition & 1 deletion e2e/__fixtures__/failing/index.test.ts
@@ -1,4 +1,4 @@
import { expectType } from 'mlh-tsd';
import { expectType } from 'tsd';
import concat from '.';

expectType<string>(concat('pre', 'fix'));
Expand Down
6 changes: 6 additions & 0 deletions e2e/__fixtures__/no-assertions/index.d.ts
@@ -0,0 +1,6 @@
/* eslint-disable no-unused-vars */
declare const concat: {
(a: string, b: string): string;
};

export default concat;
5 changes: 5 additions & 0 deletions e2e/__fixtures__/no-assertions/index.test.ts
@@ -0,0 +1,5 @@
import concat from '.';

concat('one', 'two');
concat(1, 2);
concat([1, 2]);
6 changes: 6 additions & 0 deletions e2e/__fixtures__/no-assertions/package.json
@@ -0,0 +1,6 @@
{
"jest": {
"runner": "../../../src/",
"testMatch": ["**/*.test.ts"]
}
}
2 changes: 1 addition & 1 deletion e2e/__fixtures__/passing/index.test.ts
@@ -1,4 +1,4 @@
import { expectType } from 'mlh-tsd';
import { expectType } from 'tsd';
import concat from '.';

expectType<string>(concat('pre', 'fix'));
Expand Down
2 changes: 1 addition & 1 deletion e2e/__fixtures__/pkg-types/types.test.ts
@@ -1,4 +1,4 @@
import { expectType } from 'mlh-tsd';
import { expectType } from 'tsd';
import concat from '.';

expectType<string>(concat('pre', 'fix'));
Expand Down
2 changes: 1 addition & 1 deletion e2e/__snapshots__/docblock.test.ts.snap
Expand Up @@ -4,7 +4,7 @@ exports[`reads \`@type\` comment in docblock 1`] = `
"PASS ./concat.test.ts
✓ tsd typecheck
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time:
Ran all test suites.
Expand Down
2 changes: 1 addition & 1 deletion e2e/__snapshots__/failing.test.ts.snap
Expand Up @@ -9,7 +9,7 @@ exports[`works with failing test 1`] = `
| ^
at index.test.ts:5:20
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 passed, 2 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time:
Ran all test suites.
Expand Down
21 changes: 21 additions & 0 deletions e2e/__snapshots__/no-assertions.test.ts.snap
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`runs a test file with no assertions 1`] = `
"FAIL ./index.test.ts
✕ tsd typecheck
● tsd typecheck
Argument of type 'number' is not assignable to parameter of type 'string'.
> 4 | concat(1, 2);
| ^
at index.test.ts:4:8
Expected 2 arguments, but got 1.
> 5 | concat([1, 2]);
| ^
at index.test.ts:5:1
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time:
Ran all test suites.
"
`;
2 changes: 1 addition & 1 deletion e2e/__snapshots__/passing.test.ts.snap
Expand Up @@ -4,7 +4,7 @@ exports[`works with passing test 1`] = `
"PASS ./index.test.ts
✓ tsd typecheck
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time:
Ran all test suites.
Expand Down
2 changes: 1 addition & 1 deletion e2e/__snapshots__/pkg-types.test.ts.snap
Expand Up @@ -4,7 +4,7 @@ exports[`reads \`types\` property in package.json 1`] = `
"PASS ./types.test.ts
✓ tsd typecheck
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time:
Ran all test suites.
Expand Down
6 changes: 6 additions & 0 deletions e2e/no-assertions.test.ts
@@ -0,0 +1,6 @@
import { expect, test } from '@jest/globals';
import runJest from './runJest';

test('runs a test file with no assertions', async () => {
expect(await runJest('no-assertions')).toMatchSnapshot();
});
2 changes: 1 addition & 1 deletion jest.config.js
Expand Up @@ -5,5 +5,5 @@ module.exports = {
testMatch: ['<rootDir>/e2e/*.test.ts'],
},
],
testTimeout: 30000,
testTimeout: 60000,
};
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -21,8 +21,7 @@
"chalk": "^4.1.2",
"create-jest-runner": "^0.9.0",
"graceful-fs": "^4.2.8",
"jest-docblock": "^27.0.6",
"mlh-tsd": "^0.14.1"
"jest-docblock": "^27.0.6"
},
"devDependencies": {
"@babel/core": "^7.15.8",
Expand All @@ -37,8 +36,12 @@
"execa": "^5.1.1",
"jest": "^27.2.5",
"prettier": "^2.4.1",
"tsd": "^0.18.0",
"typescript": "^4.4.4"
},
"peerDependencies": {
"tsd": ">=0.15.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It felt like peerDependencies is good idea. v0.15 is the minimal version with necessary API.

},
"prettier": {
"arrowParens": "avoid",
"singleQuote": true
Expand Down
26 changes: 0 additions & 26 deletions src/fail.js

This file was deleted.

16 changes: 0 additions & 16 deletions src/pass.js

This file was deleted.

13 changes: 3 additions & 10 deletions src/run.js
@@ -1,10 +1,9 @@
const { dirname, join, posix, relative, sep } = require('path');
const { fail, pass } = require('create-jest-runner');
const { readFileSync } = require('graceful-fs');
const { parse } = require('jest-docblock');
const tsd = require('mlh-tsd');
const tsd = require('tsd');
const formatErrorMessage = require('./formatErrorMessage');
const { pass } = require('./pass');
const { fail } = require('./fail');

const TEST_TITLE = 'tsd typecheck';

Expand Down Expand Up @@ -39,34 +38,28 @@ module.exports = async ({ config: { rootDir }, testPath }) => {

const start = Date.now();

const { diagnostics, numTests } = await tsd.default({
const diagnostics = await tsd.default({
cwd: rootDir,
testFiles: [normalizeSlashes(testFile)],
typingsFile,
});

const end = Date.now();

const numFailed = diagnostics.length;
const numPassed = numTests - numFailed;

if (diagnostics.length > 0) {
const errorMessage = formatErrorMessage(diagnostics, testFileContents);

return fail({
start,
end,
test: { path: testFile, title: TEST_TITLE },
numFailed,
numPassed,
errorMessage,
});
}

return pass({
start,
end,
numPassed,
test: { path: testFile, title: TEST_TITLE },
});
};
43 changes: 0 additions & 43 deletions src/toTestResult.js

This file was deleted.