Skip to content

Commit

Permalink
fix: Added console warning on accessing deprecated pathToJest.
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
Ross committed May 18, 2020
1 parent 379a10d commit 92d6696
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
35 changes: 35 additions & 0 deletions src/__tests__/project_workspace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
import ProjectWorkspace, {createProjectWorkspace} from '../project_workspace';

describe('setup', () => {
beforeAll(() => {
// we mock console.warn because we emit a warning when the deprecated property is used. We will
// throw away the actual message to save cluttering the test output.
jest.spyOn(global.console, 'warn').mockImplementation(() => {});
});

afterAll(() => {
jest.restoreAllMocks();
});

afterEach(() => {
// make sure the call details are reset between each test.
jest.clearAllMocks();
});

it('sets itself up fom the constructor', () => {
const workspace = new ProjectWorkspace('root_path', 'jest_command_line', 'path_to_config', 1000);
expect(workspace.rootPath).toEqual('root_path');
Expand Down Expand Up @@ -70,4 +85,24 @@ describe('setup', () => {
expect(instance.rootPath).toBe(config.rootPath);
expect(instance.pathToConfig).toBe(undefined);
});

it('accessing pathToJest invokes console warning.', () => {
const config = {
jestCommandLine: 'jestCommandLine',
localJestMajorVersion: 1000,
rootPath: 'rootPath',
collectCoverage: false,
debug: true,
outputFileSuffix: 'suffix',
};

const instance = createProjectWorkspace(config);

instance.pathToJest = 'new value';
expect(global.console.warn).toBeCalledTimes(1);

// eslint-disable-next-line no-unused-vars
const {pathToJest} = instance;
expect(global.console.warn).toBeCalledTimes(2);
});
});
7 changes: 5 additions & 2 deletions src/project_workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ export default class ProjectWorkspace {
jestCommandLine: string;

/**
* @deprecated please use `jestCommandLine` instead. If both settings are provided, only
* `jestCommandLine` will be used.
* @deprecated please use `jestCommandLine` instead.
*
* @type {string?}
*/
get pathToJest() {
// eslint-disable-next-line no-console
console.warn('Use of ProjectWorkspace.pathToJest is deprecated. Please use jestCommandLine instead.');
return this.jestCommandLine;
}

set pathToJest(commandLine: string) {
// eslint-disable-next-line no-console
console.warn('Use of ProjectWorkspace.pathToJest is deprecated. Please use jestCommandLine instead.');
this.jestCommandLine = commandLine;
}

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* Basic Options */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["ES2015"], /* Specify library files to be included in the compilation. */
"lib": ["DOM", "ES2015"], /* Specify library files to be included in the compilation. */
"allowJs": false, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
Expand Down

0 comments on commit 92d6696

Please sign in to comment.