mirror of https://github.com/status-im/metro.git
Adapt jest transform for node-only files
Summary: This changes the jest preprocessor so that files targetet at node.js will be run with the node-specific transform. It also adapts tests that relied on inline requires. Benefit: packager tests run faster now. Reviewed By: cpojer Differential Revision: D3562007 fbshipit-source-id: e06c86d545926a5c546458025f505dca115e7ea8
This commit is contained in:
parent
9d6414281e
commit
3263f18a6e
|
@ -14,10 +14,13 @@ Object.values || require('core-js/fn/object/values');
|
|||
|
||||
var _only = [];
|
||||
|
||||
module.exports = function(onlyList) {
|
||||
_only = _only.concat(onlyList);
|
||||
function registerOnly(onlyList) {
|
||||
require('babel-register')(config(onlyList));
|
||||
}
|
||||
|
||||
require('babel-register')({
|
||||
function config(onlyList) {
|
||||
_only = _only.concat(onlyList);
|
||||
return {
|
||||
presets: ['es2015-node'],
|
||||
plugins: [
|
||||
'transform-flow-strip-types',
|
||||
|
@ -25,6 +28,11 @@ module.exports = function(onlyList) {
|
|||
'transform-object-rest-spread',
|
||||
],
|
||||
only: _only,
|
||||
retainLines: true,
|
||||
sourceMaps: 'inline',
|
||||
});
|
||||
};
|
||||
babelrc: false,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = exports = registerOnly;
|
||||
exports.config = config;
|
||||
|
|
|
@ -14,12 +14,14 @@ jest.mock('../extract-dependencies');
|
|||
jest.mock('../inline');
|
||||
jest.mock('../minify');
|
||||
|
||||
const {transformCode} = require('..');
|
||||
const {any, objectContaining} = jasmine;
|
||||
|
||||
describe('code transformation worker:', () => {
|
||||
let transformCode;
|
||||
|
||||
let extractDependencies, transform;
|
||||
beforeEach(() => {
|
||||
({transformCode} = require('..'));
|
||||
extractDependencies =
|
||||
require('../extract-dependencies').mockReturnValue({});
|
||||
transform = jest.fn();
|
||||
|
@ -68,7 +70,7 @@ describe('code transformation worker:', () => {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('removes shebang when present', done => {
|
||||
const shebang = '#!/usr/bin/env node';
|
||||
const result = {
|
||||
|
@ -81,7 +83,7 @@ describe('code transformation worker:', () => {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('calls back with any error yielded by the transform', done => {
|
||||
const error = Error('arbitrary error');
|
||||
transform.mockImplementation((_, callback) => callback(error));
|
||||
|
|
|
@ -11,18 +11,18 @@
|
|||
jest.unmock('../');
|
||||
jest.mock('path');
|
||||
|
||||
const Promise = require('promise');
|
||||
const Resolver = require('../');
|
||||
|
||||
const path = require('path');
|
||||
|
||||
let DependencyGraph = jest.fn();
|
||||
const DependencyGraph = jest.fn();
|
||||
jest.setMock('node-haste', DependencyGraph);
|
||||
let Module;
|
||||
let Polyfill;
|
||||
|
||||
describe('Resolver', function() {
|
||||
let Resolver, path;
|
||||
|
||||
beforeEach(function() {
|
||||
Resolver = require('../');
|
||||
path = require('path');
|
||||
DependencyGraph.mockClear();
|
||||
Module = jest.fn(function() {
|
||||
this.getName = jest.fn();
|
||||
|
@ -131,7 +131,14 @@ describe('Resolver', function() {
|
|||
).then(function(result) {
|
||||
expect(result.mainModuleId).toEqual('index');
|
||||
expect(result.dependencies[result.dependencies.length - 1]).toBe(module);
|
||||
expect(DependencyGraph.prototype.createPolyfill.mock.calls.map((call) => call[0])).toEqual([
|
||||
expect(
|
||||
DependencyGraph
|
||||
.prototype
|
||||
.createPolyfill
|
||||
.mock
|
||||
.calls
|
||||
.map((call) => call[0]))
|
||||
.toEqual([
|
||||
{ id: 'polyfills/polyfills.js',
|
||||
file: 'polyfills/polyfills.js',
|
||||
dependencies: []
|
||||
|
|
|
@ -14,23 +14,25 @@ jest.setMock('worker-farm', function() { return () => {}; })
|
|||
.setMock('timers', { setImmediate: (fn) => setTimeout(fn, 0) })
|
||||
.setMock('uglify-js')
|
||||
.setMock('crypto')
|
||||
.setMock('source-map', { SourceMapConsumer: (fn) => {}})
|
||||
.setMock('source-map', { SourceMapConsumer: function(fn) {}})
|
||||
.mock('../../Bundler')
|
||||
.mock('../../AssetServer')
|
||||
.mock('../../lib/declareOpts')
|
||||
.mock('node-haste')
|
||||
.mock('../../Activity');
|
||||
|
||||
const Promise = require('promise');
|
||||
const SourceMapConsumer = require('source-map').SourceMapConsumer;
|
||||
|
||||
const Bundler = require('../../Bundler');
|
||||
const Server = require('../');
|
||||
const AssetServer = require('../../AssetServer');
|
||||
|
||||
let FileWatcher;
|
||||
|
||||
describe('processRequest', () => {
|
||||
let SourceMapConsumer, Bundler, Server, AssetServer, Promise;
|
||||
beforeEach(() => {
|
||||
SourceMapConsumer = require('source-map').SourceMapConsumer;
|
||||
Bundler = require('../../Bundler');
|
||||
Server = require('../');
|
||||
AssetServer = require('../../AssetServer');
|
||||
Promise = require('promise');
|
||||
});
|
||||
|
||||
let server;
|
||||
|
||||
const options = {
|
||||
|
|
Loading…
Reference in New Issue