Skip to content

Commit ac2b879

Browse files
committed
Implement object oriented API proposal
1 parent 48a5a94 commit ac2b879

File tree

20 files changed

+303
-108
lines changed

20 files changed

+303
-108
lines changed

e2e/__tests__/__snapshots__/runProgrammatically.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`runCore Jest programmatically: stdout 1`] = `"runCore success, 1 passed tests."`;
3+
exports[`createJest run programmatically: stdout 1`] = `"runCore success, 1 passed tests."`;
44

5-
exports[`runCore Jest programmatically: summary 1`] = `
5+
exports[`createJest run programmatically: summary 1`] = `
66
"Test Suites: 1 passed, 1 total
77
Tests: 1 passed, 1 total
88
Snapshots: 0 total

e2e/__tests__/__snapshots__/runProgrammaticallyMultipleProjects.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`runCLI programmatically with multiple projects: summary 1`] = `
3+
exports[`run jest programmatically with multiple projects: summary 1`] = `
44
"Test Suites: 2 passed, 2 total
55
Tests: 2 passed, 2 total
66
Snapshots: 0 total
77
Time: <<REPLACED>>
88
Ran all test suites in 2 projects."
99
`;
1010
11-
exports[`runCore programmatically with multiple projects: summary 1`] = `
11+
exports[`runCLI programmatically with multiple projects: summary 1`] = `
1212
"Test Suites: 2 passed, 2 total
1313
Tests: 2 passed, 2 total
1414
Snapshots: 0 total

e2e/__tests__/runProgrammatically.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ test('run Jest programmatically esm', () => {
2121
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[-\S]*-dev$/);
2222
});
2323

24-
test('runCore Jest programmatically', () => {
25-
const {stderr, stdout} = run('node core.mjs', dir);
24+
test('createJest run programmatically', () => {
25+
const {stderr, stdout} = run('node jest.mjs', dir);
2626
const {summary} = extractSummary(stripAnsi(stderr));
2727

2828
expect(summary).toMatchSnapshot('summary');

e2e/__tests__/runProgrammaticallyMultipleProjects.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ test('runCLI programmatically with multiple projects', () => {
1818
expect(summary).toMatchSnapshot('summary');
1919
});
2020

21-
test('runCore programmatically with multiple projects', () => {
22-
const {stderr, exitCode} = run('node run-core.js', dir);
21+
test('run jest programmatically with multiple projects', () => {
22+
const {stderr, exitCode} = run('node run-jest.js', dir);
2323
const {summary} = extractSummary(stripAnsi(stderr));
2424
expect(exitCode).toBe(0);
2525
expect(summary).toMatchSnapshot('summary');

e2e/run-programmatically-multiple-projects/run-core.js renamed to e2e/run-programmatically-multiple-projects/run-jest.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
const {runCore, readConfigs} = require('jest');
8+
const {createJest} = require('jest');
99

1010
async function main() {
11-
const {globalConfig, configs} = await readConfigs(process.argv, ['.']);
12-
13-
await runCore(
14-
{
15-
...globalConfig,
16-
collectCoverage: false,
17-
watch: false,
18-
},
19-
configs,
20-
);
11+
const jest = await createJest();
12+
jest.globalConfig = {
13+
collectCoverage: false,
14+
watch: false,
15+
...jest.globalConfig,
16+
};
17+
await jest.run();
2118
console.log('run-programmatically-core-multiple-projects completed');
2219
}
2320

e2e/run-programmatically/core.mjs renamed to e2e/run-programmatically/jest.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7-
import jest from 'jest';
7+
import jestModule from 'jest';
8+
const {createJest} = jestModule;
89

9-
const {globalConfig, configs} = await jest.readConfigs(process.argv, ['.']);
10-
const runConfig = Object.freeze({
11-
...globalConfig,
10+
const jest = await createJest();
11+
jest.globalConfig = {
1212
collectCoverage: false,
1313
watch: false,
14-
});
15-
const {results} = await jest.runCore(runConfig, configs);
14+
...jest.globalConfig,
15+
};
16+
const {results} = await jest.run();
1617
console.log(`runCore success, ${results.numPassedTests} passed tests.`);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`snapshot works with plain objects and the title has \`escape\` characters 1`] = `
4+
{
5+
"a": 1,
6+
"b": "2",
7+
"c": "three\`",
8+
"d": "vier",
9+
}
10+
`;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`snapshot is not influenced by previous counter 1`] = `
4+
{
5+
"a": 43,
6+
"b": "43",
7+
"c": "fortythree",
8+
}
9+
`;
10+
11+
exports[`snapshot works with \\r\\n 1`] = `
12+
"<div>
13+
</div>"
14+
`;
15+
16+
exports[`snapshot works with plain objects and the title has \`escape\` characters 1`] = `
17+
{
18+
"a": 1,
19+
"b": "2",
20+
"c": "three\`",
21+
}
22+
`;
23+
24+
exports[`snapshot works with plain objects and the title has \`escape\` characters 2`] = `
25+
{
26+
"a": 1,
27+
"b": "2",
28+
"c": "three\`",
29+
"d": "4",
30+
}
31+
`;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`snapshot is not influenced by previous counter 1`] = `
4+
{
5+
"a": 43,
6+
"b": "43",
7+
"c": "fortythree",
8+
}
9+
`;
10+
11+
exports[`snapshot works with \\r\\n 1`] = `
12+
"<div>
13+
</div>"
14+
`;
15+
16+
exports[`snapshot works with plain objects and the title has \`escape\` characters 1`] = `
17+
{
18+
"a": 1,
19+
"b": "2",
20+
"c": "three\`",
21+
}
22+
`;
23+
24+
exports[`snapshot works with plain objects and the title has \`escape\` characters 2`] = `
25+
{
26+
"a": 1,
27+
"b": "2",
28+
"c": "three\`",
29+
"d": "4",
30+
}
31+
`;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*/
8+
'use strict';
9+
10+
describe('snapshot', () => {
11+
it('works with plain objects and the title has `escape` characters', () => {
12+
const test = {
13+
a: 1,
14+
b: '2',
15+
c: 'three`',
16+
};
17+
expect(test).not.toBe(undefined);
18+
test.d = '4';
19+
expect(test).toMatchSnapshot();
20+
});
21+
22+
it('is not influenced by previous counter', () => {
23+
const test = {
24+
a: 43,
25+
b: '43',
26+
c: 'fortythree',
27+
};
28+
expect(test).toMatchSnapshot();
29+
});
30+
31+
it('cannot be used with .not', () => {
32+
expect(() => expect('').not.toMatchSnapshot()).toThrow(
33+
'Snapshot matchers cannot be used with not',
34+
);
35+
});
36+
37+
// Issue reported here: https://github.com/facebook/jest/issues/2969
38+
it('works with \\r\\n', () => {
39+
expect('<div>\r\n</div>').toMatchSnapshot();
40+
});
41+
});

0 commit comments

Comments
 (0)