Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
13 changes: 13 additions & 0 deletions integration-tests/__tests__/__snapshots__/each.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`runs only the describe.only.each tests 1`] = `
"PASS __tests__/describe-only.test.js
passes all rows expected true == true
✓ passes
✓ passes
fails all rows expected false == true
○ skipped 1 test

"
`;

exports[`shows error message when not enough arguments are supplied to tests 1`] = `
"FAIL __tests__/each-exception.test.js
✕ throws exception when not enough arguments are supplied $left == $right
Expand Down Expand Up @@ -41,6 +52,8 @@ exports[`shows only the tests without .skip as being ran 1`] = `
✓ passes one row expected true == true
✓ passes one row expected true == true
○ skipped 4 tests
passes all rows expected true == true
○ skipped 2 tests

"
`;
Expand Down
9 changes: 7 additions & 2 deletions integration-tests/__tests__/each.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ const runJest = require('../runJest');
const {extractSummary} = require('../Utils');
const dir = path.resolve(__dirname, '../each');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const SkipOnJestCircus = require('../../scripts/SkipOnJestCircus');

SkipOnWindows.suite();
Copy link
Contributor

Choose a reason for hiding this comment

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

btw, do we need skipping it on windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we tried removing this before and it failed 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

we should probably add a helper fixing the differing symbols on windows and unix so that the integration tests can run. separate issue, though

SkipOnJestCircus.suite();

test('works with passing tests', () => {
const result = runJest(dir, ['success.test.js']);
Expand Down Expand Up @@ -50,7 +48,14 @@ test('shows only the tests with .only as being ran', () => {

test('shows only the tests without .skip as being ran', () => {
const result = runJest(dir, ['each-skip.test.js']);
const {rest} = extractSummary(result.stderr);
expect(rest).toMatchSnapshot();
expect(result.status).toBe(0);
});

test('runs only the describe.only.each tests', () => {
const result = runJest(dir, ['describe-only.test.js']);
const {rest} = extractSummary(result.stderr);
expect(rest).toMatchSnapshot();
expect(result.status).toBe(0);
});
26 changes: 26 additions & 0 deletions integration-tests/each/__tests__/describe-only.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2018-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.
*/

describe.only.each([[true, true], [true, true]])(
'passes all rows expected %s == %s',
(left, right) => {
it('passes', () => {
expect(left).toBe(right);
});
}
);

// This failing tests should never because of the above `only` so the suite
// should pass
describe.each([[false, true]])(
'fails all rows expected %s == %s',
(left, right) => {
it('fails', () => {
expect(left).toBe(right);
});
}
);
9 changes: 9 additions & 0 deletions integration-tests/each/__tests__/each-skip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ it.skip.each`
expect(left).toBe(right);
}
);

describe.skip.each([[true, true], [true, true]])(
'passes all rows expected %s == %s',
(left, right) => {
it('passes', () => {
expect(left).toBe(right);
});
}
);
1 change: 1 addition & 0 deletions packages/jest-circus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"expect": "^23.0.0",
"is-generator-fn": "^1.0.0",
"jest-diff": "^23.0.0",
"jest-each": "^23.0.0",
"jest-matcher-utils": "^23.0.0",
"jest-message-util": "^23.0.0",
"jest-snapshot": "^23.0.0",
Expand Down
9 changes: 9 additions & 0 deletions packages/jest-circus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
BlockName,
TestName,
} from 'types/Circus';
import {bind as bindEach} from 'jest-each';
import {dispatch} from './state';

type THook = (fn: HookFn, timeout?: number) => void;
Expand Down Expand Up @@ -105,6 +106,14 @@ test.only = (testName: TestName, fn: TestFn, timeout?: number) => {
});
};

test.each = bindEach(test);
test.only.each = bindEach(test.only);
test.skip.each = bindEach(test.skip);

describe.each = bindEach(describe);
describe.only.each = bindEach(describe.only);
describe.skip.each = bindEach(describe.skip);

module.exports = {
afterAll,
afterEach,
Expand Down
13 changes: 11 additions & 2 deletions packages/jest-each/src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
/**
* Copyright (c) 2014-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
*/

import bind from './bind';
import arrayEach from './array';
import templateEach from './template';

const each = (...args) => {
const each = (...args: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use mixed type 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.

I’m AFK at the moment, I’ll update this later tonight when I get home or in another PR I’ve got a few refactors/improvements I want to make with the each code 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just tried to update to mixed and got the following flow error when trying to access args.length. I think it is fine to leave it as any

Cannot get `args.length` because property `length` is missing in mixed [1]. (index.js:15:12)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I think Array<mixed> should do the trick here, cause args is an array. Or we can be fancy and use $ReadOnlyArray<*>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice just updated :)

if (args.length > 1) {
return templateEach(global)(...args);
}

return arrayEach(global)(...args);
};

each.withGlobal = g => (...args) => {
each.withGlobal = g => (...args: any) => {
if (args.length > 1) {
return templateEach(g)(...args);
}
Expand Down