Skip to content

Commit

Permalink
Fix colorized jest output (#1601)
Browse files Browse the repository at this point in the history
* Revert "Update ava.config.js (#1582)"

This reverts commit aff9bb9.

* Try a different trick to get expect() emitting colorized diffs without permanent process.env changes

* amending
  • Loading branch information
cspotcode authored Jan 21, 2022
1 parent d5de43c commit a817289
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion ava.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ export default {
failWithoutAssertions: false,
environmentVariables: {
ts_node_install_lock: `id-${Math.floor(Math.random() * 10e9)}`,
// Force jest expect() errors to generate colorized strings, makes output more readable
// Force jest expect() errors to generate colorized strings, makes output more readable.
// Delete the env var within ava processes via `require` option below.
// This avoids passing it to spawned processes under test, which would negatively affect
// their behavior.
FORCE_COLOR: '3',
},
require: ['./src/test/remove-env-var-force-color.js'],
timeout: '300s',
};
2 changes: 1 addition & 1 deletion src/test/exec-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ChildProcess, ExecException, ExecOptions } from 'child_process';
import { exec as childProcessExec } from 'child_process';
import * as expect from 'expect';
import { expect } from './testlib';

export type ExecReturn = Promise<ExecResult> & { child: ChildProcess };
export interface ExecResult {
Expand Down
1 change: 0 additions & 1 deletion src/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type * as tsNodeTypes from '../index';
import type _createRequire from 'create-require';
import { has, once } from 'lodash';
import semver = require('semver');
import * as expect from 'expect';
const createRequire: typeof _createRequire = require('create-require');
export { tsNodeTypes };

Expand Down
1 change: 1 addition & 0 deletions src/test/remove-env-var-force-color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
delete process.env.FORCE_COLOR;
3 changes: 1 addition & 2 deletions src/test/repl/repl-environment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* globals, __filename, builtin module accessors.
*/

import { test as _test } from '../testlib';
import * as expect from 'expect';
import { test as _test, expect } from '../testlib';
import * as promisify from 'util.promisify';
import * as getStream from 'get-stream';
import {
Expand Down
3 changes: 1 addition & 2 deletions src/test/repl/repl.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { _test, expect } from '../testlib';
import { ts } from '../helpers';
import semver = require('semver');
import * as expect from 'expect';
import {
CMD_TS_NODE_WITH_PROJECT_FLAG,
contextTsNodeUnderTest,
Expand All @@ -9,7 +9,6 @@ import {
} from '../helpers';
import { createExec, createExecTester } from '../exec-helpers';
import { upstreamTopLevelAwaitTests } from './node-repl-tla';
import { _test } from '../testlib';
import { contextReplHelpers } from './helpers';
import { promisify } from 'util';

Expand Down
4 changes: 3 additions & 1 deletion src/test/testlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import avaTest, {
} from 'ava';
import * as assert from 'assert';
import throat from 'throat';
export { ExecutionContext };
import * as expect from 'expect';

export { ExecutionContext, expect };

// NOTE: this limits concurrency within a single process, but AVA launches
// each .spec file in its own process, so actual concurrency is higher.
Expand Down

0 comments on commit a817289

Please sign in to comment.