Skip to content

Commit

Permalink
ReactClassEquivalence
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov committed May 19, 2016
1 parent 530ad40 commit 49e817b
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 210 deletions.
7 changes: 6 additions & 1 deletion grunt/tasks/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ function run(done, configPath) {
grunt.util.spawn({
cmd: 'node',
args: args,
opts: { stdio: 'inherit', env: { NODE_ENV: 'test' } },
opts: {
stdio: 'inherit',
env: Object.assign({}, process.env, {
NODE_ENV: 'test',
}),
},
}, function(spawnErr, result, code) {
if (spawnErr) {
onError(spawnErr);
Expand Down
62 changes: 50 additions & 12 deletions src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,62 @@

'use strict';

var MetaMatchers = require('MetaMatchers');
var spawnSync = require('child_process').spawnSync;
var path = require('path');

describe('ReactClassEquivalence', function() {

beforeEach(function() {
this.addMatchers(MetaMatchers);
});

var es6 = () => require('./ReactES6Class-test.js');
var coffee = () => require('./ReactCoffeeScriptClass-test.coffee');
var ts = () => require('./ReactTypeScriptClass-test.ts');

it('tests the same thing for es6 classes and CoffeeScript', function() {
expect(coffee).toEqualSpecsIn(es6);
var result1 = runJest('ReactCoffeeScriptClass-test.coffee');
var result2 = runJest('ReactES6Class-test.js');
compareResults(result1, result2);
});

it('tests the same thing for es6 classes and TypeScript', function() {
expect(ts).toEqualSpecsIn(es6);
var result1 = runJest('ReactTypeScriptClass-test.ts');
var result2 = runJest('ReactES6Class-test.js');
compareResults(result1, result2);
});

});

function runJest(testFile) {
var cwd = process.cwd();
var jestBin = path.resolve('node_modules', '.bin', 'jest');
var setupFile = path.resolve(__dirname, 'setupSpecEquivalenceReporter.js');
var result = spawnSync('node', [
jestBin,
testFile,
'--setupFile',
setupFile,
], {cwd});

if (result.error) {
throw result.error;
}

if (result.status !== 0) {
throw new Error(
'jest process exited with: ' +
result.status +
'\n' +
'stdout: ' +
result.stdout.toString() +
'stderr: ' +
result.stderr.toString()
);
}

return result.stdout.toString();
}

function compareResults(a, b) {
var regexp = /^EQUIVALENCE.*$/gm;
var aSpecs = (a.match(regexp) || []).sort().join('\n');
var bSpecs = (b.match(regexp) || []).sort().join('\n');

if (aSpecs.length === 0 && bSpecs.length === 0) {
throw new Error('No spec results found in the output');
}

expect(aSpecs).toEqual(bSpecs);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*!
* Copyright 2015-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.
*/

'use strict';

var expect = global.expect;

var numExpectations = 0;

global.expect = function() {
numExpectations += 1;
return expect.apply(this, arguments);
};

beforeEach(() => numExpectations = 0);

jasmine.currentEnv_.addReporter({
specDone: (spec) => {
console.log(
`EQUIVALENCE: ${spec.description}, ` +
`status: ${spec.status}, ` +
`numExpectations: ${numExpectations}`
);
},
});
135 changes: 0 additions & 135 deletions src/test/MetaMatchers.js

This file was deleted.

62 changes: 0 additions & 62 deletions src/test/__tests__/MetaMatchers-test.js

This file was deleted.

0 comments on commit 49e817b

Please sign in to comment.