Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Add support for jest
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffmo committed May 16, 2014
1 parent 6191871 commit d2c2e4e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
11 changes: 11 additions & 0 deletions jestPreprocessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var jstransform = require('./src/jstransform');
var arrowFuncVisitors = require('./visitors/es6-arrow-function-visitors');
var restParamVisitors = require('./visitors/es6-rest-param-visitors');

exports.process = function(sourceText, sourcePath) {
return jstransform.transform(
arrowFuncVisitors.visitorList
.concat(restParamVisitors.visitorList),
sourceText
).code;
};
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,14 @@
],
"engines": {
"node": ">=0.8.8"
},
"devDependencies": {
"jest-cli": "^0.1.5"
},
"jest": {
"scriptPreprocessor": "<rootDir>/jestPreprocessor.js"
},
"scripts": {
"test": "jest"
}
}
52 changes: 32 additions & 20 deletions visitors/__tests__/es6-class-visitors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

/*jshint evil:true*/

require('mock-modules').autoMockOff();
jest.autoMockOff();

describe('es6-classes', function() {
var transformFn;
var visitors;

beforeEach(function() {
require('mock-modules').dumpCache();
visitors = require('../es6-class-visitors').visitorList;
transformFn = require('../../src/jstransform').transform;
});
Expand Down Expand Up @@ -350,7 +349,11 @@ describe('es6-classes', function() {
'class Child extends Parent {}'
].join('\n'));

eval(code);
var exports = new Function(
code + 'return {Child: Child, Parent: Parent};'
)();
var Child = exports.Child;
var Parent = exports.Parent;

expect(Child.protoProp).toBe(undefined);
expect(Child.staticProp).toBe('staticProp');
Expand All @@ -371,7 +374,11 @@ describe('es6-classes', function() {
'class Child extends true ? Parent1 : Parent2 {}'
].join('\n'));

eval(code);
var exports = new Function(
code + 'return {Parent1: Parent1, Child: Child};'
)();
var Child = exports.Child;
var Parent1 = exports.Parent1;

expect(Child.protoProp).toBe(undefined);
expect(Child.staticProp).toBe('staticProp');
Expand All @@ -394,7 +401,7 @@ describe('es6-classes', function() {
'class Child extends Parent {}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child('a', 'b');
expect(childInst.p1).toBe('a');
Expand All @@ -407,7 +414,7 @@ describe('es6-classes', function() {
'class Child extends Parent {}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child();
expect(childInst.constructor).toBe(Child);
Expand All @@ -430,7 +437,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child();
expect(childInst.p1).toBe('a');
Expand All @@ -456,7 +463,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child();
expect(childInst.p1).toBe(undefined);
Expand Down Expand Up @@ -487,7 +494,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child();
expect(childInst.counter).toBe(0);
Expand All @@ -511,7 +518,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child();
expect(childInst.getChildFoo()).toBe('foobar');
Expand All @@ -533,7 +540,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child();
expect(childInst.getChildFoo()).toBe('foobar');
Expand All @@ -556,7 +563,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child();
expect(childInst.p1).toBe('a');
Expand All @@ -580,7 +587,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child();
expect(childInst.p1).toBe(undefined);
Expand Down Expand Up @@ -712,7 +719,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child('foo', 'bar');
expect(childInst.foo).toBe('foo');
Expand Down Expand Up @@ -776,7 +783,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Foo = new Function(code + 'return Foo;')();

var fooInst = new Foo();
expect(fooInst.getOuterBar()).toBe('outer');
Expand All @@ -794,7 +801,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Foo = new Function(code + 'return Foo;')();

var fooInst = new Foo();
expect(fooInst.getStuff()).toBe(42);
Expand Down Expand Up @@ -827,7 +834,9 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var exports = new Function(code + 'return {_bar: _bar, Foo: Foo};')();
var _bar = exports._bar;
var Foo = exports.Foo;

var fooInst = new Foo();
expect(_bar._private).toBe(42);
Expand Down Expand Up @@ -906,7 +915,7 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code);
var Child = new Function(code + 'return Child;')();

var childInst = new Child();
childInst.setParentFoo('parent');
Expand Down Expand Up @@ -938,8 +947,11 @@ describe('es6-classes', function() {
'}'
].join('\n'));

eval(code1);
eval(code2);
var exports = new Function(
code1 + code2 + 'return {Parent: Parent, Child: Child};'
)();
var Parent = exports.Parent;
var Child = exports.Child;

var childInst = new Child();
childInst.setParentFoo('parent');
Expand Down

0 comments on commit d2c2e4e

Please sign in to comment.