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

Add error throwing to 'it'/'test' for incorrect arguments. #5558

Merged
merged 103 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from 102 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
6e41bcd
feat: adds error when using it or test without proper arguments
brianlmacdonald Feb 12, 2018
b551940
fix: adds more descriptive error message
brianlmacdonald Feb 12, 2018
1de43af
feat: adds tests for errors
brianlmacdonald Feb 12, 2018
f4a012e
fix: removes bad test
brianlmacdonald Feb 12, 2018
a84007f
feat: adds tests for circus and jasmine2
brianlmacdonald Feb 13, 2018
85587bd
fix: small tweaks to test names
brianlmacdonald Feb 13, 2018
325fe11
fix: adds circus test to flow ignore
brianlmacdonald Feb 13, 2018
363e590
fix: variable names for circus it
brianlmacdonald Feb 13, 2018
bf07249
chore: updates changelog.
brianlmacdonald Feb 13, 2018
918ad6d
fixes: lint error
brianlmacdonald Feb 13, 2018
d2a3668
updates: globals tests and snapshots
brianlmacdonald Feb 13, 2018
b489b37
fix: resets snapshot file
brianlmacdonald Feb 13, 2018
a873a75
fix: temp skips failing tests until further direction
brianlmacdonald Feb 13, 2018
119130c
feat: adds tests for test alias
brianlmacdonald Feb 13, 2018
1d6e12c
fix: renamed unimplemented test. Comments out rest snapshot for now.
brianlmacdonald Feb 14, 2018
29a0f0a
fix: restores rest snapshot and removes abs path from snapshot stack
brianlmacdonald Feb 15, 2018
d8eac51
fix: cleans up stack using cleanUpStackTrace
brianlmacdonald Feb 15, 2018
e09303f
fix: modifies regex in utils
brianlmacdonald Feb 15, 2018
5106800
fix: reverts utils regex
brianlmacdonald Feb 15, 2018
84d9a9b
fix: reverts line deletion in utils.
brianlmacdonald Feb 15, 2018
7815602
fix: replaces env in cleanup stack trace
brianlmacdonald Feb 15, 2018
0728d30
fix: updates utils to current version
brianlmacdonald Feb 15, 2018
b10ad04
fix: updates master
brianlmacdonald Feb 16, 2018
1ba971c
Merge remote-tracking branch 'upstream/master'
brianlmacdonald Feb 20, 2018
19d8d88
feat: adds error when using it or test without proper arguments
brianlmacdonald Feb 12, 2018
af8efd7
fix: adds more descriptive error message
brianlmacdonald Feb 12, 2018
30ccac2
feat: adds tests for errors
brianlmacdonald Feb 12, 2018
1842a5d
fix: removes bad test
brianlmacdonald Feb 12, 2018
17d3050
feat: adds tests for circus and jasmine2
brianlmacdonald Feb 13, 2018
754bf38
fix: small tweaks to test names
brianlmacdonald Feb 13, 2018
5464098
fix: adds circus test to flow ignore
brianlmacdonald Feb 13, 2018
42ef481
fix: variable names for circus it
brianlmacdonald Feb 13, 2018
fdc0dc3
chore: updates changelog.
brianlmacdonald Feb 13, 2018
e986609
updates: globals tests and snapshots
brianlmacdonald Feb 13, 2018
a6ab7b0
fix: resets snapshot file
brianlmacdonald Feb 13, 2018
5453e9f
fix: temp skips failing tests until further direction
brianlmacdonald Feb 13, 2018
1520b94
feat: adds tests for test alias
brianlmacdonald Feb 13, 2018
193cdf6
fix: renamed unimplemented test. Comments out rest snapshot for now.
brianlmacdonald Feb 14, 2018
b2ac1c5
fix: restores rest snapshot and removes abs path from snapshot stack
brianlmacdonald Feb 15, 2018
5ad1768
fix: cleans up stack using cleanUpStackTrace
brianlmacdonald Feb 15, 2018
0312138
fix: modifies regex in utils
brianlmacdonald Feb 15, 2018
ca714e7
fix: reverts utils regex
brianlmacdonald Feb 15, 2018
1a4dd3a
fix: reverts line deletion in utils.
brianlmacdonald Feb 15, 2018
a1ea320
fix: replaces env in cleanup stack trace
brianlmacdonald Feb 15, 2018
ef31915
fix: addresses patch
brianlmacdonald Feb 20, 2018
5e0aabd
fix: replaces overly long packages path for CI test
brianlmacdonald Feb 20, 2018
30aa554
fix: adds new snapshot after packages fix
brianlmacdonald Feb 20, 2018
735bbc2
fix: updates globals snapshot after packages fix
brianlmacdonald Feb 20, 2018
9514c32
fix: finalizes globals snapshot
brianlmacdonald Feb 20, 2018
edc9231
fix: reverses bad snapshot commit
brianlmacdonald Feb 20, 2018
d5aa613
fix: adds missing cli snapshot
brianlmacdonald Feb 20, 2018
0a560ed
fix: bad snap commit
brianlmacdonald Feb 20, 2018
911c6e1
fix: format test name bad commit
brianlmacdonald Feb 20, 2018
07a51fb
fix: adds back trailing newline
brianlmacdonald Feb 20, 2018
281100c
Merge remote-tracking branch 'upstream/master'
brianlmacdonald Feb 21, 2018
ca02d0a
updates master
brianlmacdonald Feb 22, 2018
6e351e7
feat: adds error when using it or test without proper arguments
brianlmacdonald Feb 12, 2018
7eca76f
fix: adds more descriptive error message
brianlmacdonald Feb 12, 2018
f85f956
feat: adds tests for errors
brianlmacdonald Feb 12, 2018
e64357e
fix: removes bad test
brianlmacdonald Feb 12, 2018
f2359e0
feat: adds tests for circus and jasmine2
brianlmacdonald Feb 13, 2018
4aa3101
fix: small tweaks to test names
brianlmacdonald Feb 13, 2018
139973b
fix: adds circus test to flow ignore
brianlmacdonald Feb 13, 2018
c0c478e
fix: variable names for circus it
brianlmacdonald Feb 13, 2018
ba03582
chore: updates changelog.
brianlmacdonald Feb 13, 2018
061dab3
updates: globals tests and snapshots
brianlmacdonald Feb 13, 2018
7195e05
fix: resets snapshot file
brianlmacdonald Feb 13, 2018
e411607
fix: temp skips failing tests until further direction
brianlmacdonald Feb 13, 2018
5163ee3
feat: adds tests for test alias
brianlmacdonald Feb 13, 2018
e0ff615
fix: renamed unimplemented test. Comments out rest snapshot for now.
brianlmacdonald Feb 14, 2018
29a3d64
fix: restores rest snapshot and removes abs path from snapshot stack
brianlmacdonald Feb 15, 2018
85f359e
fix: cleans up stack using cleanUpStackTrace
brianlmacdonald Feb 15, 2018
426cb07
fix: modifies regex in utils
brianlmacdonald Feb 15, 2018
895f57e
fix: reverts utils regex
brianlmacdonald Feb 15, 2018
e6f8d6a
fix: reverts line deletion in utils.
brianlmacdonald Feb 15, 2018
4547c55
fix: replaces env in cleanup stack trace
brianlmacdonald Feb 15, 2018
5c1d541
fix: resolves rebase conflict
brianlmacdonald Feb 21, 2018
dd36839
feat: adds tests for errors
brianlmacdonald Feb 12, 2018
873671a
fix: removes bad test
brianlmacdonald Feb 12, 2018
b36f4fb
fix: rebase conflict resolved
brianlmacdonald Feb 21, 2018
07154b3
fix: variable names for circus it
brianlmacdonald Feb 13, 2018
2b664de
fix: temp skips failing tests until further direction
brianlmacdonald Feb 13, 2018
17d2f77
feat: adds tests for test alias
brianlmacdonald Feb 13, 2018
b867548
fix: renamed unimplemented test. Comments out rest snapshot for now.
brianlmacdonald Feb 14, 2018
b27c0b5
fix: restores rest snapshot and removes abs path from snapshot stack
brianlmacdonald Feb 15, 2018
58e973b
fix: cleans up stack using cleanUpStackTrace
brianlmacdonald Feb 15, 2018
f1df10b
fix: modifies regex in utils
brianlmacdonald Feb 15, 2018
7648643
fix: reverts utils regex
brianlmacdonald Feb 15, 2018
c612bca
fix: reverts line deletion in utils.
brianlmacdonald Feb 15, 2018
feaaf58
fix: replaces env in cleanup stack trace
brianlmacdonald Feb 15, 2018
7378e67
fix: addresses patch
brianlmacdonald Feb 20, 2018
6e2d789
fix: replaces overly long packages path for CI test
brianlmacdonald Feb 20, 2018
bf4e287
fix: adds new snapshot after packages fix
brianlmacdonald Feb 20, 2018
ba0c286
fix: updates globals snapshot after packages fix
brianlmacdonald Feb 20, 2018
8e746b4
fix: reverses bad snapshot commit
brianlmacdonald Feb 20, 2018
f92e725
fix: adds missing cli snapshot
brianlmacdonald Feb 20, 2018
7ab85b1
fix: format test name bad commit
brianlmacdonald Feb 20, 2018
c1753b3
fix: adds back trailing newline
brianlmacdonald Feb 20, 2018
b5985e1
fix: removes redundant BUILD path. updates snapshots
brianlmacdonald Feb 22, 2018
e03c1a7
fix: resolves remote changes
brianlmacdonald Feb 22, 2018
06875a8
fix: deletes empty file, updates changelog
brianlmacdonald Feb 23, 2018
661496b
Merge branch 'master' into feat/iterrorthrowing
brianlmacdonald Feb 23, 2018
f3f1213
fix: handle flow ignores in circus tests
thymikee Feb 23, 2018
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
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ignore]
.*/examples/.*
.*/node_modules/metro-bundler/.*
.*/circus_it_test_error.test.js*.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wait, this is not supposed to be here

Copy link
Contributor Author

@brianlmacdonald brianlmacdonald Feb 23, 2018

Choose a reason for hiding this comment

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

@thymikee it's so the jest-circus tests can check the error for a missing or incorrect argument. If Flow is on for this file it won't run the test. I'm happy to go about this in another manner, if you'd rather.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just remove the @flow pragma from circus test. Let's keep this config as clean as possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thymikee

        'integration-tests/__tests__/**/*',
        'packages/babel-jest/**/*.test.js',
        'packages/babel-plugin-jest-hoist/**/*.test.js',
        'packages/babel-preset-jest/**/*.test.js',
        'packages/eslint-config-fb-strict/**/*.test.js',
        'packages/eslint-plugin-jest/**/*.test.js',
        'packages/jest-changed-files/**/*.test.js',
       ===> 'packages/jest-circus/**/*.test.js',<====
        'packages/jest-diff/**/*.test.js',
        'packages/jest-docblock/**/*.test.js',
        'packages/jest-editor-support/**/*.test.js',
        'packages/jest/**/*.test.js',
        'packages/pretty-format/**/*.test.js',
      ],
      rules: {
        'flowtype/require-valid-file-annotation': [2, 'always'],
      },

The lint config throws an error during yarn test. Can I remove this line? Or add the test file to the lint ignore? Or an exception to the rule?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope. The problem with this and previous approach is that it's easy to forget we have this "exception", which may lead to falsy feel of confidence about our codebase. I've pushed a commit with a proper, in my opinion, change for this case 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome! $FlowFixMe: is something I'll have to remember. Thanks!


[options]
module.name_mapper='^pretty-format$' -> '<PROJECT_ROOT>/packages/pretty-format/src/index.js'
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### Features

* `[jest-jasmine2]` Adds error throwing and descriptive errors to `it`/ `test`
for invalid arguements. `[jest-circus]` Adds error throwing and descriptive
errors to `it`/ `test` for invalid arguements.
* `[jest-matcher-utils]` Add `isNot` option to `matcherHint` function
([#5512](https://github.com/facebook/jest/pull/5512))

Expand Down
4 changes: 3 additions & 1 deletion integration-tests/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ const extractSummary = (stdout: string) => {
// unifies their output to make it possible to snapshot them.
// TODO: Remove when we drop support for node 4
const cleanupStackTrace = (output: string) => {
return output.replace(/^.*at.*[\s][\(]?(\S*\:\d*\:\d*).*$/gm, ' at $1');
return output
.replace(/.*(?=packages)/g, ' at ')
Copy link
Member

Choose a reason for hiding this comment

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

needed?

Copy link
Contributor Author

@brianlmacdonald brianlmacdonald Feb 20, 2018

Choose a reason for hiding this comment

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

@SimenB , that's to truncate the overly long relative path that jest-message-util generates between the __test__ folder and jest itself when it runs the integration tests for global.test.js . Looks like this on my machine with it:

packages/jest-jasmine2/build/jasmine/Env.js:433:15

and like this without it:

../../../../../../../Users/brian/Documents/projects/opensource/jest/packages/jest-jasmine2/build/jasmine/Env.js:4

It's needed for snapshots in the CI tests, so it can pass on any computer. I can add a comment in there explaining if you think it warrants it? Or try a different approach if you'd rather.

.replace(/^.*at.*[\s][\(]?(\S*\:\d*\:\d*).*$/gm, ' at $1');
};

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ exports[`works with async failures 1`] = `
+ \\"foo\\": \\"bar\\",
}

at ../../packages/expect/build/index.js:104:76
at packages/expect/build/index.js:104:76

"
`;
Expand Down
123 changes: 71 additions & 52 deletions integration-tests/__tests__/__snapshots__/globals.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,77 @@ Ran all test suites.
"
`;

exports[`cannot test with no implementation 1`] = `
"FAIL __tests__/only-constructs.test.js
● Test suite failed to run

Missing second argument. It must be a callback function.

1 |
2 | it('it', () => {});
> 3 | it('it, no implementation');
4 | test('test, no implementation');
5 |

at packages/jest-jasmine2/build/jasmine/Env.js:390:15
at __tests__/only-constructs.test.js:3:5

"
`;

exports[`cannot test with no implementation 2`] = `
"Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
"
`;

exports[`cannot test with no implementation with expand arg 1`] = `
"FAIL __tests__/only-constructs.test.js
● Test suite failed to run

Missing second argument. It must be a callback function.

1 |
2 | it('it', () => {});
> 3 | it('it, no implementation');
4 | test('test, no implementation');
5 |

at packages/jest-jasmine2/build/jasmine/Env.js:390:15
at __tests__/only-constructs.test.js:3:5

"
`;

exports[`cannot test with no implementation with expand arg 2`] = `
"Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
"
`;

exports[`function as descriptor 1`] = `
"PASS __tests__/function-as-descriptor.test.js
Foo
✓ it

"
`;

exports[`function as descriptor 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
"
`;

exports[`only 1`] = `
"PASS __tests__/only-constructs.test.js
✓ test.only
Expand Down Expand Up @@ -121,55 +192,3 @@ Time: <<REPLACED>>
Ran all test suites.
"
`;

exports[`tests with no implementation 1`] = `
"PASS __tests__/only-constructs.test.js
✓ it
○ skipped 2 tests

"
`;

exports[`tests with no implementation 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 2 skipped, 1 passed, 3 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
"
`;

exports[`tests with no implementation with expand arg 1`] = `
"PASS __tests__/only-constructs.test.js
✓ it
○ it, no implementation
○ test, no implementation

"
`;

exports[`tests with no implementation with expand arg 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 2 skipped, 1 passed, 3 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
"
`;

exports[`function as descriptor 1`] = `
"PASS __tests__/function-as-descriptor.test.js
Foo
✓ it

"
`;

exports[`function as descriptor 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
"
`;
9 changes: 5 additions & 4 deletions integration-tests/__tests__/globals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ test('only', () => {
expect(summary).toMatchSnapshot();
});

test('tests with no implementation', () => {
test('cannot test with no implementation', () => {
const filename = 'only-constructs.test.js';
const content = `
it('it', () => {});
Expand All @@ -120,9 +120,10 @@ test('tests with no implementation', () => {

writeFiles(TEST_DIR, {[filename]: content});
const {stderr, status} = runJest(DIR);
expect(status).toBe(0);
expect(status).toBe(1);

const {summary, rest} = extractSummary(stderr);

expect(rest).toMatchSnapshot();
expect(summary).toMatchSnapshot();
});
Expand Down Expand Up @@ -188,7 +189,7 @@ test('only with expand arg', () => {
expect(summary).toMatchSnapshot();
});

test('tests with no implementation with expand arg', () => {
test('cannot test with no implementation with expand arg', () => {
const filename = 'only-constructs.test.js';
const content = `
it('it', () => {});
Expand All @@ -198,7 +199,7 @@ test('tests with no implementation with expand arg', () => {

writeFiles(TEST_DIR, {[filename]: content});
const {stderr, status} = runJest(DIR, ['--expand']);
expect(status).toBe(0);
expect(status).toBe(1);

const {summary, rest} = extractSummary(stderr);
expect(rest).toMatchSnapshot();
Expand Down
75 changes: 75 additions & 0 deletions packages/jest-circus/src/__tests__/circus_it_test_error.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* *@flow
*/

'use strict';

let circusIt;
let circusTest;

//using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
//the two with this aliaser.

const aliasCircusIt = () => {
const {it, test} = require('../index.js');
circusIt = it;
circusTest = test;
};

aliasCircusIt();

//A few of these tests require incorrect types to throw errors and thus pass
//the test. The typechecks on jest-circus would prevent that, so
//this file has been listed in the .flowconfig ignore section.

describe('test/it error throwing', () => {
it(`it doesn't throw an error with valid arguments`, () => {
expect(() => {
circusIt('test1', () => {});
}).not.toThrowError();
});
it(`it throws error with missing callback function`, () => {
expect(() => {
circusIt('test2');
}).toThrowError('Missing second argument. It must be a callback function.');
});
it(`it throws an error when first argument isn't a string`, () => {
expect(() => {
circusIt(() => {});
}).toThrowError(`Invalid first argument, () => {}. It must be a string.`);
});
it('it throws an error when callback function is not a function', () => {
expect(() => {
circusIt('test4', 'test4b');
}).toThrowError(
`Invalid second argument, test4b. It must be a callback function.`,
);
});
it(`test doesn't throw an error with valid arguments`, () => {
expect(() => {
circusTest('test5', () => {});
}).not.toThrowError();
});
it(`test throws error with missing callback function`, () => {
expect(() => {
circusTest('test6');
}).toThrowError('Missing second argument. It must be a callback function.');
});
it(`test throws an error when first argument isn't a string`, () => {
expect(() => {
circusTest(() => {});
}).toThrowError(`Invalid first argument, () => {}. It must be a string.`);
});
it('test throws an error when callback function is not a function', () => {
expect(() => {
circusTest('test8', 'test8b');
}).toThrowError(
`Invalid second argument, test8b. It must be a callback function.`,
);
});
});
18 changes: 16 additions & 2 deletions packages/jest-circus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,22 @@ const beforeAll = (fn: HookFn) => _addHook(fn, 'beforeAll');
const afterEach = (fn: HookFn) => _addHook(fn, 'afterEach');
const afterAll = (fn: HookFn) => _addHook(fn, 'afterAll');

const test = (testName: TestName, fn?: TestFn) =>
dispatch({fn, name: 'add_test', testName});
const test = (testName: TestName, fn: TestFn) => {
if (typeof testName !== 'string') {
throw new Error(
`Invalid first argument, ${testName}. It must be a string.`,
);
}
if (fn === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

It is legal to not pass second argument, I use it as test placeholders.

Might be a a good idea to have an explicit test.todo for that case, though

throw new Error('Missing second argument. It must be a callback function.');
}
if (typeof fn !== 'function') {
throw new Error(
`Invalid second argument, ${fn}. It must be a callback function.`,
);
}
return dispatch({fn, name: 'add_test', testName});
};
const it = test;
test.skip = (testName: TestName, fn?: TestFn) =>
dispatch({fn, mode: 'skip', name: 'add_test', testName});
Expand Down
46 changes: 46 additions & 0 deletions packages/jest-jasmine2/src/__tests__/it_test_error.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

'use strict';

describe('test/it error throwing', () => {
it(`it throws error with missing callback function`, () => {
expect(() => {
it('test1');
}).toThrowError('Missing second argument. It must be a callback function.');
});
it(`it throws an error when first argument isn't a string`, () => {
expect(() => {
it(() => {});
}).toThrowError(`Invalid first argument, () => {}. It must be a string.`);
});
it('it throws an error when callback function is not a function', () => {
expect(() => {
it('test3', 'test3b');
}).toThrowError(
`Invalid second argument, test3b. It must be a callback function.`,
);
});
test(`test throws error with missing callback function`, () => {
expect(() => {
test('test4');
}).toThrowError('Missing second argument. It must be a callback function.');
});
test(`test throws an error when first argument isn't a string`, () => {
expect(() => {
test(() => {});
}).toThrowError(`Invalid first argument, () => {}. It must be a string.`);
});
test('test throws an error when callback function is not a function', () => {
expect(() => {
test('test6', 'test6b');
}).toThrowError(
`Invalid second argument, test6b. It must be a callback function.`,
);
});
});
15 changes: 15 additions & 0 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,21 @@ export default function(j$) {
};

this.it = function(description, fn, timeout) {
if (typeof description !== 'string') {
throw new Error(
`Invalid first argument, ${description}. It must be a string.`,
);
}
if (fn === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, cool. So to clarify: add an it.todo and test.todo to ignore cases like

test.todo('justOneArgument')

but still throw the error for test('justOneArgument')?

Copy link
Member

Choose a reason for hiding this comment

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

I think "yes", but it's too breaking. But I think we should do it for the next version.

(I'm all for adding test/it.todo now - though probably in a separate PR)

@cpojer thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about test.todo, let's discuss that separately. I'm definitely on board with making test/it with one argument throw. I do not consider it a breaking change but rather a bug fix, so it's fine to go into a minor.

Copy link
Member

Choose a reason for hiding this comment

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

fair enough 🙂

throw new Error(
'Missing second argument. It must be a callback function.',
);
}
if (typeof fn !== 'function') {
throw new Error(
`Invalid second argument, ${fn}. It must be a callback function.`,
);
}
const spec = specFactory(
description,
fn,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-message-util/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type StackTraceOptions = {
};

const PATH_NODE_MODULES = `${path.sep}node_modules${path.sep}`;
const PATH_EXPECT_BUILD = `${path.sep}expect${path.sep}build${path.sep}`;
const PATH_JEST_PACKAGES = `${path.sep}jest${path.sep}packages${path.sep}`;
Copy link
Member

Choose a reason for hiding this comment

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

this will make actual errors in the jest code base harder to track down when developing.

If that's ok, we should delete line 48 as well, as it's covered by this (ref https://github.com/facebook/jest/pull/5094/files#r157363023)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Let me know if I have the all clear to remove 48 & 49.

Copy link
Member

Choose a reason for hiding this comment

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

If tests are still green, it'd be great to remove both. But 49 should cover what 48 does, so only 49 is needed


// filter for noisy stack trace lines
const JASMINE_IGNORE = /^\s+at(?:(?:.*?vendor\/|jasmine\-)|\s+jasmine\.buildExpectationResult)/;
Expand Down Expand Up @@ -220,7 +220,7 @@ const formatPaths = (

const getTopFrame = (lines: string[]) => {
for (const line of lines) {
if (line.includes(PATH_NODE_MODULES) || line.includes(PATH_EXPECT_BUILD)) {
if (line.includes(PATH_NODE_MODULES) || line.includes(PATH_JEST_PACKAGES)) {
continue;
}

Expand Down