Skip to content

Commit fba4dc0

Browse files
committed
Added tests for experiment.js
1 parent 23ddd09 commit fba4dc0

5 files changed

Lines changed: 115 additions & 4 deletions

File tree

lib/server/controller.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ var logger = require("../logger");
1010
var Experiment = require('../experiment');
1111
var Project = require('../project');
1212
var Assets = require('../assets');
13-
var UglifyJS = require('uglify-js');
1413

1514
function LocalController(variation, port) {
1615
this.variation = variation;

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"lodash": "^2.4.1",
3131
"optimizely-node-client": "^0.1.0",
3232
"promptly": "^0.2.0",
33-
"q": "^1.1.2",
34-
"uglify-js": "^2.4.23"
33+
"q": "^1.1.2"
3534
},
3635
"engines": {
3736
"node": "^0.10.32"

test/commands/create-experiment.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//Test the experiment command
2+
23
var fs = require('fs');
34

45
var assert = require('chai').assert;

test/experiment.test.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
var fs = require('fs');
2+
var expect = require('chai').expect;
3+
var proxyquire = require('proxyquire');
4+
var quickTemp = require('quick-temp');
5+
var functionCalls = [];
6+
7+
/**
8+
* Used to push any function calls and their
9+
* arguments to the funcitonCalls array. We
10+
* can use this function to replace any
11+
* function calls that we aren't trying to
12+
* test.
13+
* @param {String} functionName name of the function being called
14+
* @param {Object} [returnObject] object to return after recording the funciton call
15+
* @return {Function} function that when called will record functionName and it's arguments
16+
*/
17+
var recordFunctionCalls = function(functionName, returnObject){
18+
return function(){
19+
var callRecorder = {functionName : functionName};
20+
for(var i = 0; i < arguments.length; i++){
21+
callRecorder[i] = arguments[i];
22+
}
23+
functionCalls.push(callRecorder);
24+
return returnObject;
25+
};
26+
};
27+
28+
var directories, experimentData, ExperimentTwo, experiment;
29+
var folder = 'new-experiment';
30+
var description = 'My new experiment';
31+
var edit_url = 'http://www.example.com';
32+
33+
var createExperimentWithDefaults = function(){
34+
directories = {}
35+
quickTemp.makeOrRemake(directories, 'experiment');
36+
experimentData = {
37+
description : description,
38+
edit_url : edit_url
39+
};
40+
ExperimentTwo = require('../lib/experiment.js');
41+
ExperimentTwo.create(experimentData, directories.experiment);
42+
};
43+
44+
45+
describe('Experiment', function (){
46+
47+
describe('#create()', function() {
48+
var Experiment;
49+
before(function (done) {
50+
var fileUtil = {
51+
writeDir: recordFunctionCalls('writeDir'),
52+
writeText: recordFunctionCalls('writeText'),
53+
writeJSON: recordFunctionCalls('writeJSON')
54+
};
55+
var optcliBase = require('../lib/optcli-base.js');
56+
optcliBase.prototype
57+
Experiment = proxyquire('../lib/experiment.js', {
58+
'./file-util' : fileUtil
59+
});
60+
functionCalls = [];
61+
experiment = Experiment.create({
62+
description: description,
63+
edit_url: edit_url
64+
}, folder);
65+
done();
66+
});
67+
after(function(){
68+
console.log(functionCalls.length);
69+
})
70+
it('Should create an experiment directory', function (){
71+
expect(functionCalls[0]).to.deep.equal({'functionName':'writeDir',0: folder});
72+
});
73+
it('Should create a global.css file', function(){
74+
expect(functionCalls[1]).to.deep.equal({'functionName':'writeText', 0: folder + '/global.css'});
75+
});
76+
it('Should create a global.js file', function(){
77+
expect(functionCalls[2]).to.deep.equal({'functionName':'writeText', 0: folder + '/global.js'});
78+
});
79+
it('Should create an experiment.json file', function(){
80+
expect(functionCalls[3]).to.deep.equal({
81+
'functionName':'writeJSON',
82+
0: folder + '/experiment.json',
83+
1: {
84+
'description': description,
85+
'edit_url': edit_url
86+
}
87+
});
88+
});
89+
it('Should return an experiment object', function(){
90+
expect(experiment).to.be.an.instanceOf(Experiment);
91+
});
92+
});
93+
describe('#locateAndLoad()', function(){
94+
before(function(done){
95+
createExperimentWithDefaults();
96+
console.log(functionCalls.length);
97+
experiment = ExperimentTwo.locateAndLoad(directories.experiment);
98+
done();
99+
});
100+
after(function(done){
101+
quickTemp.remove(directories, 'experiment');
102+
done();
103+
})
104+
it('Should locate the experiment.json', function(){
105+
//expect(experiment).to.be.an.instanceOf(Experiment);
106+
});
107+
it('Should load the experiment.json', function(){
108+
//expect(experiment.attributes).to.deep.equal(experimentData);
109+
});
110+
});
111+
describe('#getCSS',function(){})
112+
});

test/mocha.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
--recursive
1+
22
--ui bdd

0 commit comments

Comments
 (0)