Skip to content

Commit

Permalink
ReactClassEquivalence
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov committed May 14, 2016
1 parent 46bd294 commit bf01b1c
Show file tree
Hide file tree
Showing 4 changed files with 44 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
50 changes: 38 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,50 @@

'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 result = spawnSync('node', [jestBin, testFile, '--verbose'], {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 aSpecs = (a.match(/it\s.*$/gm) || []).sort().join('\n');
var bSpecs = (b.match(/it\s.*$/gm) || []).sort().join('\n');
expect(aSpecs).toEqual(bSpecs);
}
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 bf01b1c

Please sign in to comment.