Skip to content

Commit

Permalink
normalize icons and slashes across OSes (#6310)
Browse files Browse the repository at this point in the history
* try to run more tests on windows

* normalize slashes in in test filenames and log output

* fix jest config test

* update changelog
  • Loading branch information
SimenB authored May 27, 2018
1 parent d59017d commit d5dd58c
Show file tree
Hide file tree
Showing 37 changed files with 30 additions and 107 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Fixes

* `[expect]` toMatchObject throws TypeError when a source property is null ([#6313](https://github.com/facebook/jest/pull/6313))
* `[jest-cli]` Normalize slashes in paths in CLI output on Windows ((#6310)[https://github.com/facebook/jest/pull/6310])

## 23.0.1

Expand Down
22 changes: 12 additions & 10 deletions integration-tests/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ const linkJestPackage = (packageName: string, cwd: Path) => {
fs.symlinkSync(packagePath, destination, 'dir');
};

const fileExists = (filePath: Path) => {
try {
fs.accessSync(filePath, fs.F_OK);
return true;
} catch (e) {
return false;
}
};

const makeTemplate = (str: string): ((values?: Array<any>) => string) => {
return (values: ?Array<any>) => {
return str.replace(/\$(\d+)/g, (match, number) => {
Expand Down Expand Up @@ -175,14 +166,25 @@ const cleanupStackTrace = (output: string) => {
.replace(/^.*at.*[\s][\(]?(\S*\:\d*\:\d*).*$/gm, ' at $1');
};

const normalizeIcons = (str: string) => {
if (!str) {
return str;
}

// Make sure to keep in sync with `jest-cli/src/constants`
return str
.replace(new RegExp('\u00D7', 'g'), '\u2715')
.replace(new RegExp('\u221A', 'g'), '\u2713');
};

module.exports = {
cleanup,
copyDir,
createEmptyPackage,
extractSummary,
fileExists,
linkJestPackage,
makeTemplate,
normalizeIcons,
run,
writeFiles,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`traverses directory tree up until it finds jest.config 1`] = `
" console.log ../../../__tests__/a-banana.js:3
" console.log ../../../__tests__/a-banana.js:4
<<REPLACED>>/jest.config.js/some/nested/directory
"
`;
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/compare_dom_nodes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
*/
'use strict';

const SkipOnWindows = require('../../scripts/SkipOnWindows');
const runJest = require('../runJest');

SkipOnWindows.suite();

test('does not crash when expect involving a DOM node fails', () => {
const result = runJest('compare-dom-nodes');

Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/console.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@

'use strict';

const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {extractSummary} = require('../Utils');
const runJest = require('../runJest');

SkipOnWindows.suite();

test('console printing', () => {
const {stderr, status} = runJest('console');
const {summary, rest} = extractSummary(stderr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
'use strict';

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {extractSummary, cleanup, writeFiles} = require('../Utils');
const runJest = require('../runJest');

const DIR = path.resolve(__dirname, '../console_log_output_when_run_in_band');

SkipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/coverage_report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@

const fs = require('fs');
const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {extractSummary} = require('../Utils');
const runJest = require('../runJest');

const DIR = path.resolve(__dirname, '../coverage-report');

SkipOnWindows.suite();

test('outputs coverage report', () => {
const {stdout, status} = runJest(DIR, ['--no-cache', '--coverage']);
const coverageDir = path.resolve(__dirname, '../coverage-report/coverage');
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/coverage_threshold.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
'use strict';

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {cleanup, writeFiles} = require('../Utils');
const runJest = require('../runJest');

const DIR = path.resolve(__dirname, '../coverage-threshold');

SkipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

const runJest = require('../runJest');
const {extractSummary} = require('../Utils');
const SkipOnWindows = require('../../scripts/SkipOnWindows');

SkipOnWindows.suite();

test('works with custom matchers', () => {
const {stderr} = runJest('custom-matcher-stack-trace');
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/custom_reporters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
'use strict';

const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {cleanup, extractSummary, writeFiles} = require('../Utils');
const runJest = require('../runJest');
const os = require('os');
Expand All @@ -20,8 +19,6 @@ beforeEach(() => cleanup(DIR));
afterEach(() => cleanup(DIR));

describe('Custom Reporters Integration', () => {
SkipOnWindows.suite();

test('valid string format for adding reporters', () => {
const reporterConfig = {
reporters: ['<rootDir>/reporters/TestReporter.js'],
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/debug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
*/

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const runJest = require('../runJest');

describe('jest --debug', () => {
SkipOnWindows.suite();

const dir = path.resolve(__dirname, '..', 'verbose-reporter');

it('outputs debugging info before running the test', () => {
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/__tests__/each.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ const path = require('path');
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();
SkipOnJestCircus.suite();

test('works with passing tests', () => {
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/execute-tests-once-in-mpr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
'use strict';

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {extractSummary, cleanup, writeFiles} = require('../Utils');
const runJest = require('../runJest');

const DIR = path.resolve(__dirname, '../execute-tests-once-in-mpr');

SkipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/expect-async-matcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
'use strict';

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const runJest = require('../runJest');
const {extractSummary} = require('../Utils');
const dir = path.resolve(__dirname, '../expect-async-matcher');

SkipOnWindows.suite();

test('works with passing tests', () => {
const result = runJest(dir, ['success.test.js']);
expect(result.status).toBe(0);
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/failures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
*/

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {extractSummary} = require('../Utils');
const runJest = require('../runJest');

const dir = path.resolve(__dirname, '../failures');

const normalizeDots = text => text.replace(/\.{1,}$/gm, '.');

SkipOnWindows.suite();

function cleanStderr(stderr) {
const {rest} = extractSummary(stderr);
return rest
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/find_related_files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ import path from 'path';

const {cleanup, writeFiles, extractSummary} = require('../Utils');

const SkipOnWindows = require('../../scripts/SkipOnWindows');
const DIR = path.resolve(os.tmpdir(), 'find_related_tests_test');

SkipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterEach(() => cleanup(DIR));

Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/force_exit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import os from 'os';
import path from 'path';
const {cleanup, writeFiles} = require('../Utils');

const SkipOnWindows = require('../../scripts/SkipOnWindows');
const DIR = path.resolve(os.tmpdir(), 'force_exit_test');

SkipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterEach(() => cleanup(DIR));

Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/globals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@

const path = require('path');
const os = require('os');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const runJest = require('../runJest');
const {extractSummary} = require('../Utils');
const {createEmptyPackage, writeFiles, cleanup} = require('../Utils');

const DIR = path.resolve(os.tmpdir(), 'global-variables.test');
const TEST_DIR = path.resolve(DIR, '__tests__');

SkipOnWindows.suite();

function cleanStderr(stderr) {
const {rest} = extractSummary(stderr);
return rest.replace(/.*(jest-jasmine2|jest-circus).*\n/g, '');
Expand Down
6 changes: 2 additions & 4 deletions integration-tests/__tests__/jest.config.js.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
'use strict';

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {extractSummary, cleanup, writeFiles} = require('../Utils');
const runJest = require('../runJest');

const DIR = path.resolve(__dirname, '../jest.config.js');

SkipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

Expand All @@ -38,8 +35,9 @@ test('works with jest.config.js', () => {
test('traverses directory tree up until it finds jest.config', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `
const slash = require('slash');
test('banana', () => expect(1).toBe(1));
test('abc', () => console.log(process.cwd()));
test('abc', () => console.log(slash(process.cwd())));
`,
'jest.config.js': `module.exports = {testRegex: '.*-banana.js'};`,
'package.json': '{}',
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/jest_require_actual.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@

const path = require('path');
const os = require('os');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {cleanup, writeFiles} = require('../Utils');
const runJest = require('../runJest');

const DIR = path.resolve(os.tmpdir(), 'jest_require_actual_test');

SkipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/jest_require_mock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@

const path = require('path');
const os = require('os');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {cleanup, writeFiles} = require('../Utils');
const runJest = require('../runJest');

const DIR = path.resolve(os.tmpdir(), 'jest_require_mock_test');

SkipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/log_heap_usage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@

const path = require('path');
const os = require('os');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {cleanup, writeFiles} = require('../Utils');
const runJest = require('../runJest');

const DIR = path.resolve(os.tmpdir(), 'log_heap_usage_test');

SkipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

Expand Down
4 changes: 0 additions & 4 deletions integration-tests/__tests__/module_name_mapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
'use strict';

const runJest = require('../runJest');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {extractSummary} = require('../Utils');

// Works on windows, we just need to adjust snapshot test output
SkipOnWindows.suite();

test('moduleNameMapper wrong configuration', () => {
const {stderr, status} = runJest('module-name-mapper-wrong-config');
const {rest} = extractSummary(stderr);
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/multi_project_runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ import path from 'path';
import stripAnsi from 'strip-ansi';

const {cleanup, extractSummary, writeFiles} = require('../Utils');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const DIR = path.resolve(os.tmpdir(), 'multi_project_runner_test');

SkipOnWindows.suite();

const fileContentWithProvidesModule = name => `/*
* @providesModule ${name}
*/
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/run_tests_by_path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import os from 'os';
import path from 'path';
const {cleanup, writeFiles} = require('../Utils');

const SkipOnWindows = require('../../scripts/SkipOnWindows');
const DIR = path.resolve(os.tmpdir(), 'run_tests_by_path_test');

SkipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterEach(() => cleanup(DIR));

Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const path = require('path');
const {extractSummary} = require('../Utils');
const runJest = require('../runJest');

const SkipOnWindows = require('../../scripts/SkipOnWindows');
SkipOnWindows.suite();

const emptyTest = 'describe("", () => {it("", () => {})})';
const snapshotDir = path.resolve(
__dirname,
Expand Down
Loading

0 comments on commit d5dd58c

Please sign in to comment.