Skip to content

Commit

Permalink
Move the typescript parser outside of jest-editor-support to jest-tes… (
Browse files Browse the repository at this point in the history
jestjs#2973)

* Move the typescript parser outside of jest-editor-support to jest-test-typescript-parser

* Move the fixture folder on the top level

* rename babylonParser to parse and export TypeScript from jest-test-typescript-parser index.js

* make node 4 happy.
  • Loading branch information
kentaromiura authored and cpojer committed Feb 23, 2017
1 parent f6bc9d8 commit f67fc6d
Show file tree
Hide file tree
Showing 22 changed files with 69 additions and 58 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

'use strict';

import type {ParserReturn} from '../../ScriptParser';
const fixtures = __dirname;

const path = require('path');
const fixtures = path.resolve(__dirname, '../fixtures');

function parserTests(parse: (file: string) => ParserReturn) {
function parserTests(parse: (file: string) => any) {
describe('File parsing without throwing', () => {
it('Should not throw', () => {
expect(() => {
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-editor-support/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
},
"license": "BSD-3-Clause",
"main": "build/index.js",
"peerDependencies": {
"typescript": "^2.0.10"
},
"dependencies": {
"babylon": "^6.13.0"
},
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-editor-support/src/Process.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ module.exports.createProcess = (
// as they can only be the first command, so take out the command, and add
// any other bits into the args
const runtimeExecutable = workspace.pathToJest;
const [command, ...initialArgs] = runtimeExecutable.split(' ');
const runtimeArgs = [...initialArgs, ...args];
const parameters = runtimeExecutable.split(' ');
const command = parameters[0];
const initialArgs = parameters.slice(1);
const runtimeArgs = [].concat(initialArgs, args);

// If a path to configuration file was defined, push it to runtimeArgs
const configPath = workspace.pathToConfig;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-editor-support/src/__tests__/Runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

const {EventEmitter} = require('events');
const path = require('path');
const fixtures = path.resolve(__dirname, 'fixtures');
const fixtures = path.resolve(__dirname, '../../../../fixtures');
const ProjectWorkspace = require('../ProjectWorkspace');

const {readFileSync} = require('fs');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
const TestReconciler = require('../TestReconciler');
const fs = require('fs');
const path = require('path');
const fixtures = path.resolve(__dirname, 'fixtures');
const fixtures = path.resolve(__dirname, '../../../../fixtures');

const reconcilerWithFile = (file: string): TestReconciler => {
const parser = new TestReconciler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

'use strict';

const {babylonParser} = require('../../parsers/BabylonParser');
const {parserTests} = require('./parserTests');
const {parse} = require('../../parsers/BabylonParser');
const {parserTests} = require('../../../../../fixtures/parserTests');

parserTests(babylonParser);
parserTests(parse);
2 changes: 1 addition & 1 deletion packages/jest-editor-support/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ProjectWorkspace = require('./ProjectWorkspace');
const Runner = require('./Runner');
const Settings = require('./Settings');
const {Expect, ItBlock, Node} = require('./parsers/ParserNodes');
const {parse} = require('./ScriptParser');
const {parse} = require('./parsers/BabylonParser');
const TestReconciler = require('./TestReconciler');

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-editor-support/src/parsers/BabylonParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const getBabelRC = (filename, {useCache}) => {
return cache[directory] || '';
};

const babylonParser = (file: string) => {
const parse = (file: string) => {
const itBlocks: ItBlock[] = [];
const expects: Expect[] = [];

Expand Down Expand Up @@ -196,5 +196,5 @@ const babylonParser = (file: string) => {
};

module.exports = {
babylonParser,
parse,
};
3 changes: 3 additions & 0 deletions packages/jest-test-typescript-parser/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/__mocks__/**
**/__tests__/**
src
14 changes: 14 additions & 0 deletions packages/jest-test-typescript-parser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "jest-test-typescript-parser",
"version": "19.0.1",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git"
},
"license": "BSD-3-Clause",
"main": "build/index.js",
"dependencies": {
"jest-editor-support": "^19.0.1",
"typescript": "^2.0.10"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

const ts = require('typescript');
const {readFileSync} = require('fs');
const {Expect, ItBlock, Node} = require('./ParserNodes');
const {Expect, ItBlock, Node} = require('jest-editor-support');

function parse(file: string) {
const sourceFile = ts.createSourceFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

'use strict';

const {parse} = require('../../parsers/TypeScriptParser');
const {parserTests} = require('./parserTests');
const {parse} = require('../TypeScriptParser');
const {parserTests} = require('../../../../fixtures/parserTests');

parserTests(parse);
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
/**
* 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.
*
* @flow
*/

'use strict';

const {babylonParser} = require('./parsers/BabylonParser');
const {ItBlock, Expect} = require('./parsers/ParserNodes.js');

export type ParserReturn = {
itBlocks: Array<ItBlock>,
expects: Array<Expect>,
};

/**
* Converts the file into an AST, then passes out a
* collection of it and expects.
*/
function parse(file: string): ParserReturn {
if (file.match(/\.tsx?$/)) {
// This require is done here so that it can be optional for clients
const {parse} = require('./parsers/TypeScriptParser');
return parse(file);
} else {
return babylonParser(file);
}
}

module.exports = {
parse,
};
/**
* 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.
*
* @flow
*/

'use strict';

const {parse: babylonParser, ItBlock, Expect} = require('jest-editor-support');
const TypeScriptParser = require('./TypeScriptParser');
export type ParserReturn = {
itBlocks: Array<ItBlock>,
expects: Array<Expect>,
};

/**
* Converts the file into an AST, then passes out a
* collection of it and expects.
*/
function parse(file: string): ParserReturn {
if (file.match(/\.tsx?$/)) {
return TypeScriptParser.parse(file);
} else {
return babylonParser(file);
}
}

module.exports = {
TypeScriptParser,
parse,
};

0 comments on commit f67fc6d

Please sign in to comment.