Skip to content

Commit

Permalink
tweak test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 9, 2018
1 parent d39a7c7 commit 799b4e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
21 changes: 4 additions & 17 deletions packages/jest-cli/src/__tests__/run_jest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,22 @@ import runJest from '../runJest';

jest.mock('jest-util');

const processErrWriteFn = process.stderr.write;
describe('runJest', () => {
let stderrSpy;
beforeEach(async () => {
process.exit = jest.fn();
process.stderr.write = jest.fn();
process.stderr.write.mockReset();
stderrSpy = jest.spyOn(process.stderr, 'write');
test('when watch is set then print error and exit process', async () => {
jest.spyOn(process, 'exit').mockImplementation(() => {});

await runJest({
changedFilesPromise: Promise.resolve({repos: {git: {size: 0}}}),
changedFilesPromise: Promise.resolve({repos: {git: new Set()}}),
contexts: [],
globalConfig: {watch: true},
onComplete: () => null,
outputStream: {},
startRun: {},
testWatcher: {isInterrupted: () => true},
});
});

afterEach(() => {
process.stderr.write = processErrWriteFn;
});
await new Promise(process.nextTick);

test('when watch is set then exit process', () => {
expect(process.exit).toHaveBeenCalledWith(1);
});

test('when watch is set then an error message is printed', () => {
expect(stderrSpy).toHaveBeenCalled();
});
});
12 changes: 6 additions & 6 deletions packages/jest-runner/src/run_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ async function runTestInternal(
const originalStdOutWrite = testStdOut.write;
const originalStdErrWrite = testStdErr.write;

testStdOut.write = (chunk, ...rest) => {
testStdOut.write = (chunk, encoding, ...rest) => {
const type = 'write';
const message = chunk.toString();
const message = chunk.toString(encoding);
const api = 'process.stdout';

if (buffer) {
Expand All @@ -162,12 +162,12 @@ async function runTestInternal(
consoleOut.write(consoleFormatter(type, message, api, 3));
}

return originalStdOutWrite.call(testStdOut, chunk, ...rest);
return originalStdOutWrite.call(testStdOut, chunk, encoding, ...rest);
};

testStdErr.write = (chunk, ...rest) => {
testStdErr.write = (chunk, encoding, ...rest) => {
const type = 'write';
const message = chunk.toString();
const message = chunk.toString(encoding);
const api = 'process.stderr';

if (buffer) {
Expand All @@ -183,7 +183,7 @@ async function runTestInternal(
consoleOut.write(consoleFormatter(type, message, api, 3));
}

return originalStdErrWrite.call(testStdErr, chunk, ...rest);
return originalStdErrWrite.call(testStdErr, chunk, encoding, ...rest);
};

const environment = new TestEnvironment(config, {console: testConsole});
Expand Down

0 comments on commit 799b4e1

Please sign in to comment.