Skip to content

Commit 4140d15

Browse files
committed
test examples with globals
1 parent 34480f3 commit 4140d15

9 files changed

+86
-23
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
tslint.json
33
src/*.ts
4+
test/**/*.ts
45
tsconfig.json
56
typings
67
tsd.json

src/createRunner.js renamed to src/create-runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
2-
var spawn = require('child_process').spawn;
32
var path = require('path');
3+
var spawn = require('child_process').spawn;
44
function createRunner(config, tests) {
55
var options = {
66
cwd: config.dir

src/runner.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
22
var utils_1 = require('./utils');
3-
var createRunner_1 = require('./createRunner');
3+
var create_runner_1 = require('./create-runner');
44
function runner(files, config, handleResult, handleLog) {
55
var tests = utils_1.concatAll(files);
6-
var runner = createRunner_1.createRunner(config, tests);
6+
var runner = create_runner_1.createRunner(config, tests);
77
var result = {
88
pass: false,
99
taskPosition: 0,

test/context/array-method.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var answer = data.filter(function(x) {
2+
return x.name === 'A';
3+
});

test/context/data.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
{
2-
"a": 42
3-
}
1+
[{
2+
"name": "A"
3+
}, {
4+
"name": "B"
5+
}, {
6+
"name": "C"
7+
}]

test/load-context.spec.js

+44-14
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,49 @@ describe('loadContext', function() {
3838
return expect(run).to.eventually.deep.equal(expected);
3939
});
4040

41-
it('should allowing requiring files', function() {
42-
var files = [
43-
['load-context-03.js']
44-
];
45-
var run = getRunner(files);
46-
var expected = {
47-
pass: true,
48-
taskPosition: 1,
49-
failedAtFile: null,
50-
msg: 'load-context-03 should pass'
51-
};
52-
53-
return expect(run).to.eventually.deep.equal(expected);
54-
});
41+
it('should allowing requiring files', function() {
42+
var files = [
43+
['load-context-03.js']
44+
];
45+
var run = getRunner(files);
46+
var expected = {
47+
pass: true,
48+
taskPosition: 1,
49+
failedAtFile: null,
50+
msg: 'load-context-03 should pass'
51+
};
52+
53+
return expect(run).to.eventually.deep.equal(expected);
54+
});
55+
56+
it('should allowing passing globals to the context', function() {
57+
var files = [
58+
['load-file-01.js']
59+
];
60+
var run = getRunner(files);
61+
var expected = {
62+
pass: true,
63+
taskPosition: 1,
64+
failedAtFile: null,
65+
msg: 'load-file-01 should pass'
66+
};
67+
68+
return expect(run).to.eventually.deep.equal(expected);
69+
});
70+
71+
it('should allowing passing globals to the context', function() {
72+
var files = [
73+
['load-file-02.js']
74+
];
75+
var run = getRunner(files);
76+
var expected = {
77+
pass: true,
78+
taskPosition: 1,
79+
failedAtFile: null,
80+
msg: 'load-file-02 should pass'
81+
};
82+
83+
return expect(run).to.eventually.deep.equal(expected);
84+
});
5585

5686
});

test/tests/load-context-03.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ var path = require('path');
33
var loadContext = require('../utils/loadContext').default;
44
loadContext('./context/addOne.js');
55
loadContext('./context/subtractOne.js');
6-
var a = JSON.parse(JSON.stringify(require('../context/data.json'))).a;
6+
var a = JSON.parse(JSON.stringify(require('../context/data.json')));
77

88
describe('load-context-03', function () {
99

1010
it('should pass', function () {
11-
expect(addOne(a)).to.equal(43);
12-
expect(subtractOne(a)).to.equal(41);
11+
expect(a[0]).to.deep.equal({name: 'A'});
1312
});
1413

1514
});

test/tests/load-file-01.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var expect = require('chai').expect;
2+
var path = require('path');
3+
var loadContext = require('../utils/loadContext').default;
4+
global.data = JSON.parse(JSON.stringify(require('../context/data.json')));
5+
loadContext('./context/array-method.js');
6+
7+
describe('load-file-01', function () {
8+
9+
it('should pass', function () {
10+
expect(answer).to.deep.equal([{name: 'A'}]);
11+
});
12+
13+
});

test/tests/load-file-02.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var expect = require('chai').expect;
2+
var path = require('path');
3+
var loadContext = require('../utils/loadContext').default;
4+
data = JSON.parse(JSON.stringify(require('../context/data.json')));
5+
loadContext('./context/array-method.js');
6+
7+
describe('load-file-02', function () {
8+
9+
it('should pass', function () {
10+
expect(answer).to.deep.equal([{name: 'A'}]);
11+
});
12+
13+
});

0 commit comments

Comments
 (0)