Skip to content

Commit

Permalink
Added jest-repl test (jestjs#1198)
Browse files Browse the repository at this point in the history
- Fixed bug in jest-runtime test
- Fixed linter errors
  • Loading branch information
sampepose authored and cpojer committed Jun 21, 2016
1 parent 8fb13b0 commit e5c1559
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions packages/jest-repl/src/__tests__/jest-repl-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
*/
'use strict';

const spawnSync = require('child_process').spawnSync;
const path = require('path');

const JEST_RUNTIME = path.resolve(__dirname, '../../bin/jest-repl.js');

jest.disableAutomock();

describe('Repl', () => {
describe('cli', () => {
it('runs without errors', () => {
const output = spawnSync(JEST_RUNTIME, [], {
encoding: 'utf8',
cwd: process.cwd(),
env: process.env,
});
const expectedRegex = new RegExp([
'Using Jest Runtime v([0-9]+.[0-9]+.[0-9]+), ',
'Jest REPL v([0-9]+.[0-9]+.[0-9]+)',
].join(''));
expect(output.stdout.trim()).toMatch(expectedRegex);
});
});
});
4 changes: 2 additions & 2 deletions packages/jest-repl/src/cli/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const evalCommand = (cmd, context, filename, callback, config) => {
return callback(isRecoverableError(e) ? new repl.Recoverable(e) : e);
}
return callback(null, result);
}
};

const isRecoverableError = error => {
if (error && error.name === 'SyntaxError') {
Expand All @@ -51,7 +51,7 @@ const isRecoverableError = error => {
].some(exception => error.message.includes(exception));
}
return false;
}
};

if (jestConfig.scriptPreprocessor) {
/* $FlowFixMe */
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runtime/src/__tests__/Runtime-cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Runtime', () => {
cwd: process.cwd(),
env: process.env,
});
expect(output.stdout.trim()).toBe('Hello, world!');
expect(output.stdout.trim()).toMatch('Hello, world!');
});

it('throws script errors', () => {
Expand Down

0 comments on commit e5c1559

Please sign in to comment.