Skip to content

Commit

Permalink
fix: review nits
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed Dec 3, 2020
1 parent c9ecf36 commit 7c73368
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion e2e/__tests__/babelPluginJestDeadlines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import runJest from '../runJest';

const DIR = path.resolve(__dirname, '..', 'babel-plugin-jest-deadlines');

beforeEach(() => {
beforeAll(() => {
runYarnInstall(DIR);
});

Expand Down
8 changes: 2 additions & 6 deletions packages/babel-plugin-jest-deadlines/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@
"./package.json": "./package.json"
},
"dependencies": {
"@babel/template": "^7.3.3",
"@babel/types": "^7.3.3",
"@types/babel__core": "^7.0.0",
"@types/babel__traverse": "^7.0.6"
"@types/babel__core": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/preset-react": "^7.12.1",
"@types/babel__template": "^7.0.2",
"@types/node": "*",
"@types/prettier": "^2.0.0",
"babel-plugin-tester": "^10.0.0",
"prettier": "^2.1.1"
"babel-plugin-tester": "^10.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
exports[`babel-plugin-jest-deadlines bare function call in statement context: bare function call in statement context 1`] = `
async function foo() {
await bar();
}
await bar();
}
↓ ↓ ↓ ↓ ↓ ↓
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ pluginTester({
tests: {
'bare function call in statement context': {
// language=JavaScript
code: `async function foo() {
await bar();
}`,
code: `
async function foo() {
await bar();
}`,
snapshot: true,
},
'transforms an expression': {
Expand Down
3 changes: 0 additions & 3 deletions packages/babel-plugin-jest-deadlines/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
*/

import type {PluginObj, types as babelTypes} from '@babel/core';
import type {Identifier} from '@babel/types';

export default ({
types: t,
}: {
types: typeof babelTypes;
}): PluginObj<{
declareJestObjGetterIdentifier: () => Identifier;
jestObjGetterIdentifier?: Identifier;
}> => ({
visitor: {
AwaitExpression(path) {
Expand Down
1 change: 1 addition & 0 deletions packages/expect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ setMatchers(spyMatchers, true, expect as Expect);
setMatchers(toThrowMatchers, true, expect as Expect);

expect.addSnapshotSerializer = () => void 0;
expect.withinDeadline = async () => { throw new Error('withinDeadline must be implemented by the runtime'); }
expect.assertions = assertions;
expect.hasAssertions = hasAssertions;
expect.getState = getState;
Expand Down
7 changes: 5 additions & 2 deletions packages/jest-circus/src/deadlineTimeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ function isUs(line: string): boolean {
}

async function timeout<T>(promise: Promise<T>, ms: number): Promise<T> {
let timeoutId;
let timeoutId: ReturnType<typeof setTimeout> | undefined;
try {
return await Promise.race([
promise,
(async () => {
await new Promise(resolve => {
timeoutId = setTimeout(resolve, ms);
});
timeoutId = undefined;
const here = new Error(`deadline exceeded (waited here for ${ms}ms)`);
here.stack = here.stack
?.split('\n')
Expand All @@ -30,6 +31,8 @@ async function timeout<T>(promise: Promise<T>, ms: number): Promise<T> {
})(),
]);
} finally {
clearTimeout(timeoutId);
if (timeoutId) {
clearTimeout(timeoutId);
}
}
}
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4882,15 +4882,11 @@ __metadata:
dependencies:
"@babel/core": ^7.11.6
"@babel/preset-react": ^7.12.1
"@babel/template": ^7.3.3
"@babel/types": ^7.3.3
"@types/babel__core": ^7.0.0
"@types/babel__template": ^7.0.2
"@types/babel__traverse": ^7.0.6
"@types/node": "*"
"@types/prettier": ^2.0.0
babel-plugin-tester: ^10.0.0
prettier: ^2.1.1
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 7c73368

Please sign in to comment.