Skip to content

Commit b25b3d7

Browse files
author
benholloway
committed
split added javascript and css specs in order to run the test spec properly
1 parent ee674b8 commit b25b3d7

File tree

7 files changed

+243
-61
lines changed

7 files changed

+243
-61
lines changed

test/expected/minimal-es5-unminified/app-test/karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
module.exports = function(config) {
88
config.set({
99
// base path, that will be used to resolve files and exclude
10-
basePath: '/Users/benholloway/Documents/WebstormProjects/angularity/node-angularity/test/expected/minimal-es5',
10+
basePath: '%redacted%',
1111

1212
//make sure we use karma-jasmine as the test framework
1313
frameworks: ['jasmine'],
@@ -41,7 +41,7 @@ module.exports = function(config) {
4141
// installation and thus need to be registered manually
4242
// append to existing value to preserve plugins loaded automatically
4343
plugins: [].concat(config.plugins).concat([
44-
require("/Users/benholloway/Documents/WebstormProjects/angularity/node-angularity/node_modules/karma-angularity-reporter")
44+
require("%redacted%")
4545
]),
4646

4747
// use dots reporter, as travis terminal does not support escaping sequences

test/expected/minimal-es5/app-test/karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
module.exports = function(config) {
88
config.set({
99
// base path, that will be used to resolve files and exclude
10-
basePath: '/Users/benholloway/Documents/WebstormProjects/angularity/node-angularity/test/expected/minimal-es5',
10+
basePath: '%redacted%',
1111

1212
//make sure we use karma-jasmine as the test framework
1313
frameworks: ['jasmine'],
@@ -41,7 +41,7 @@ module.exports = function(config) {
4141
// installation and thus need to be registered manually
4242
// append to existing value to preserve plugins loaded automatically
4343
plugins: [].concat(config.plugins).concat([
44-
require("/Users/benholloway/Documents/WebstormProjects/angularity/node-angularity/node_modules/karma-angularity-reporter")
44+
require("%redacted%")
4545
]),
4646

4747
// use dots reporter, as travis terminal does not support escaping sequences

test/specs/tasks/build.spec.js

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
var diffMatchers = require('jasmine-diff-matchers');
44

5-
var helper = require('../../helpers/angularity-test'),
6-
matchers = require('../../helpers/jasmine-matchers');
5+
var helper = require('../../helpers/angularity-test'),
6+
matchers = require('../../helpers/jasmine-matchers'),
7+
javascriptSpec = require('./javascript.spec.js'),
8+
cssSpec = require('./css.spec.js');
79

810
var fastIt = helper.jasmineFactory({
911
before: 0,
@@ -22,6 +24,10 @@ describe('The Angularity build task', function () {
2224

2325
beforeEach(matchers.addMatchers);
2426

27+
beforeEach(javascriptSpec.customMatchers);
28+
29+
beforeEach(cssSpec.customMatchers);
30+
2531
beforeEach(customMatchers);
2632

2733
beforeEach(helper.getTimeoutSwitch(60000));
@@ -41,7 +47,7 @@ describe('The Angularity build task', function () {
4147
function expectations(testCase) {
4248
expect([testCase.cwd, BUILD_FOLDER]).toBeEmptyDirectory();
4349
expect([testCase.cwd, TEST_FOLDER ]).toBeEmptyDirectory();
44-
expect(testCase.stderr).toBeHelpWithError(false);
50+
expect(testCase.stderr).toBeBuildHelpWithError(false);
4551
}
4652
});
4753

@@ -70,55 +76,22 @@ describe('The Angularity build task', function () {
7076
function expectations(testCase) {
7177
var workingBuildFile = helper.getConcatenation(testCase.cwd, BUILD_FOLDER);
7278
var sourceBuildFile = helper.getConcatenation(testCase.sourceDir, BUILD_FOLDER);
73-
var workingTestFile = helper.getConcatenation(testCase.cwd, TEST_FOLDER);
74-
var sourceTestFile = helper.getConcatenation(testCase.sourceDir, TEST_FOLDER);
75-
76-
// general
77-
if (/test/.test(testCase.command)) { // TODO @bholloway test should inherit JS not build
78-
expect(testCase.stdout).toBeTask('javascript');
79-
} else {
80-
expect(testCase.stdout).toBeTask(['build', 'javascript', 'css']);
81-
}
82-
expect(testCase.cwd).toHaveExpectedItemsExcept();
83-
84-
// build output
79+
expect(testCase.stdout).toBeTask('build');
80+
expect(testCase.cwd).toHaveFile('app-build/index.html');
8581
expect(workingBuildFile('index.html')).diffFilePatch(sourceBuildFile('index.html'));
86-
expect(workingBuildFile('index.js')).diffFilePatch(sourceBuildFile('index.js'));
87-
expect(workingBuildFile('index.css')).diffFilePatch(sourceBuildFile('index.css'));
88-
// expect(workingBuildFile('index.js.map' )).diffFilePatch(sourceBuildFile('index.js.map')); // TODO @bholloway solve repeatability of .map files
89-
// expect(workingBuildFile('index.css.map')).diffFilePatch(sourceBuildFile('index.css.map')); // TODO @bholloway solve repeatability of .map files
90-
91-
// must remove basePath to allow karma.conf.js to be correctly diff'd
92-
var replace = helper.replacer()
93-
.add(/^\s*basePath:.*$/gm, '')
94-
.add(/^\s*require\(.*$/gm, '')
95-
.add(/\\{2}/g, '/')
96-
.commit();
97-
98-
// test output
99-
if (/test/.test(testCase.command)) {
100-
expect(replace(workingTestFile('karma.conf.js'))).diffPatch(replace(sourceTestFile('karma.conf.js'))); // TODO @bholloway reporter differs between build and test tasks
101-
}
102-
expect(workingTestFile('index.js')).diffFilePatch(sourceTestFile('index.js'));
103-
// expect(workingTestFile('index.js.map')).diffFilePatch(sourceTestFile('index.js.map')); // TODO @bholloway solve repeatability of .map files
82+
javascriptSpec.expectations(testCase);
83+
cssSpec.expectations(testCase);
10484
}
10585

10686
function customMatchers() {
10787
jasmine.addMatchers(diffMatchers.diffPatch);
10888
jasmine.addMatchers({
109-
toBeHelpWithError : matchers
110-
.getHelpMatcher(/^\s*The "build" task/),
111-
toHaveExpectedItemsExcept: matchers
112-
.getFileMatcher(
113-
'app-build/index.html',
114-
'app-build/index.js', 'app-build/index.js.map',
115-
'app-build/index.css', 'app-build/index.css.map',
116-
'app-test/karma.conf.js',
117-
'app-test/index.js', 'app-test/index.js.map'
118-
)
89+
toBeBuildHelpWithError : matchers
90+
.getHelpMatcher(/^\s*The "build" task/)
11991
});
12092
}
12193

12294
module.exports = {
123-
expectations: expectations
95+
expectations : expectations,
96+
customMatchers: customMatchers
12497
};

test/specs/tasks/css.spec.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
'use strict';
2+
3+
var diffMatchers = require('jasmine-diff-matchers');
4+
5+
var helper = require('../../helpers/angularity-test'),
6+
matchers = require('../../helpers/jasmine-matchers');
7+
8+
var fastIt = helper.jasmineFactory({
9+
before: 0,
10+
after : 500
11+
});
12+
13+
var slowIt = helper.jasmineFactory({
14+
before: 500,
15+
after : 1000
16+
});
17+
18+
var BUILD_FOLDER = 'app-build';
19+
20+
describe('The Angularity css task', function () {
21+
22+
beforeEach(matchers.addMatchers);
23+
24+
beforeEach(customMatchers);
25+
26+
beforeEach(helper.getTimeoutSwitch(60000));
27+
28+
afterEach(helper.getTimeoutSwitch());
29+
30+
afterEach(helper.cleanUp);
31+
32+
describe('should display help when requested', function (done) {
33+
helper.runner.create()
34+
.addInvocation('css --help')
35+
.addInvocation('css -h')
36+
// .addInvocation('css -?') // TODO @bholloway process cannot be spawned on windows when it has -? flag
37+
.forEach(fastIt(expectations))
38+
.finally(done);
39+
40+
function expectations(testCase) {
41+
expect([testCase.cwd, BUILD_FOLDER]).toBeEmptyDirectory();
42+
expect(testCase.stderr).toBeCssHelpWithError(false);
43+
}
44+
});
45+
46+
describe('should compile css correctly', function(done) {
47+
helper.runner.create()
48+
.addSource('minimal-es5')
49+
.addInvocation('css')
50+
.forEach(slowIt(expectations))
51+
.finally(done);
52+
});
53+
});
54+
55+
function expectations(testCase) {
56+
var workingBuildFile = helper.getConcatenation(testCase.cwd, BUILD_FOLDER);
57+
var sourceBuildFile = helper.getConcatenation(testCase.sourceDir, BUILD_FOLDER);
58+
expect(testCase.stdout).toBeTask('css');
59+
expect(testCase.cwd).toHaveExpectedCssExcept();
60+
expect(workingBuildFile('index.css')).diffFilePatch(sourceBuildFile('index.css'));
61+
// expect(workingBuildFile('index.css.map')).diffFilePatch(sourceBuildFile('index.css.map')); // TODO @bholloway solve repeatability of .map files
62+
}
63+
64+
function customMatchers() {
65+
jasmine.addMatchers(diffMatchers.diffPatch);
66+
jasmine.addMatchers({
67+
toBeCssHelpWithError : matchers
68+
.getHelpMatcher(/^\s*The "css" task/),
69+
toHaveExpectedCssExcept: matchers
70+
.getFileMatcher('app-build/index.css', 'app-build/index.css.map')
71+
});
72+
}
73+
74+
module.exports = {
75+
expectations : expectations,
76+
customMatchers: customMatchers
77+
};
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
'use strict';
2+
3+
var diffMatchers = require('jasmine-diff-matchers');
4+
5+
var helper = require('../../helpers/angularity-test'),
6+
matchers = require('../../helpers/jasmine-matchers');
7+
8+
var fastIt = helper.jasmineFactory({
9+
before: 0,
10+
after : 500
11+
});
12+
13+
var slowIt = helper.jasmineFactory({
14+
before: 500,
15+
after : 1000
16+
});
17+
18+
var BUILD_FOLDER = 'app-build';
19+
var TEST_FOLDER = 'app-test';
20+
21+
describe('The Angularity javascript task', function () {
22+
23+
beforeEach(matchers.addMatchers);
24+
25+
beforeEach(customMatchers);
26+
27+
beforeEach(helper.getTimeoutSwitch(60000));
28+
29+
afterEach(helper.getTimeoutSwitch());
30+
31+
afterEach(helper.cleanUp);
32+
33+
describe('should display help when requested', function (done) {
34+
helper.runner.create()
35+
.addInvocation('javascript --help')
36+
.addInvocation('javascript -h')
37+
// .addInvocation('javascript -?') // TODO @bholloway process cannot be spawned on windows when it has -? flag
38+
.forEach(fastIt(expectations))
39+
.finally(done);
40+
41+
function expectations(testCase) {
42+
expect([testCase.cwd, BUILD_FOLDER]).toBeEmptyDirectory();
43+
expect([testCase.cwd, TEST_FOLDER ]).toBeEmptyDirectory();
44+
expect(testCase.stderr).toBeJsHelpWithError(false);
45+
}
46+
});
47+
48+
describe('should operate minified (by default)', function(done) {
49+
helper.runner.create()
50+
.addSource('minimal-es5')
51+
.addInvocation('javascript')
52+
.addInvocation('javascript --unminified false')
53+
.addInvocation('javascript -u false')
54+
.forEach(slowIt(expectations))
55+
.finally(done);
56+
});
57+
58+
describe('should operate unminified', function(done) {
59+
helper.runner.create()
60+
.addSource('minimal-es5-unminified')
61+
.addInvocation('javascript --unminified')
62+
.addInvocation('javascript -u')
63+
.addInvocation('javascript --unminified true')
64+
.addInvocation('javascript -u true')
65+
.forEach(slowIt(expectations))
66+
.finally(done);
67+
});
68+
});
69+
70+
function expectations(testCase) {
71+
var workingBuildFile = helper.getConcatenation(testCase.cwd, BUILD_FOLDER);
72+
var sourceBuildFile = helper.getConcatenation(testCase.sourceDir, BUILD_FOLDER);
73+
var workingTestFile = helper.getConcatenation(testCase.cwd, TEST_FOLDER);
74+
var sourceTestFile = helper.getConcatenation(testCase.sourceDir, TEST_FOLDER);
75+
76+
// general
77+
expect(testCase.stdout).toBeTask('javascript');
78+
expect(testCase.cwd).toHaveExpectedJsExcept();
79+
80+
// build output
81+
expect(workingBuildFile('index.js')).diffFilePatch(sourceBuildFile('index.js'));
82+
// expect(workingBuildFile('index.js.map' )).diffFilePatch(sourceBuildFile('index.js.map')); // TODO @bholloway solve repeatability of .map files
83+
84+
// test output
85+
expect(workingTestFile('index.js')).diffFilePatch(sourceTestFile('index.js'));
86+
// expect(workingTestFile('index.js.map')).diffFilePatch(sourceTestFile('index.js.map')); // TODO @bholloway solve repeatability of .map files
87+
88+
// karma configuration differs between build and test
89+
if (/test/.test(testCase.command)) {
90+
91+
// make replacements to allow karma.conf.js to be correctly diff'd
92+
var replace = helper.replacer()
93+
.add(/^(\s*basePath\:\s*['"])[^'"]*(['"].*)$/gm, '$1%redacted%$2') // basePath should be redacted
94+
.add(/^(\s*require\(['"])[^'"]*(['"].*)$/gm, '$1%redacted%$2') // all require paths should be redacted
95+
.add(/\\{2}/g, '/')
96+
.commit();
97+
expect(replace(workingTestFile('karma.conf.js'))).diffPatch(replace(sourceTestFile('karma.conf.js')));
98+
}
99+
}
100+
101+
function customMatchers() {
102+
jasmine.addMatchers(diffMatchers.diffPatch);
103+
jasmine.addMatchers({
104+
toBeJsHelpWithError : matchers
105+
.getHelpMatcher(/^\s*The "javascript" task/),
106+
toHaveExpectedJsExcept: matchers
107+
.getFileMatcher(
108+
'app-build/index.js', 'app-build/index.js.map',
109+
'app-test/index.js', 'app-test/index.js.map',
110+
'app-test/karma.conf.js'
111+
)
112+
});
113+
}
114+
115+
module.exports = {
116+
expectations : expectations,
117+
customMatchers: customMatchers
118+
};

test/specs/tasks/release.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function expectations(testCase) {
7373
var sourceVendorFile = helper.getConcatenation(testCase.sourceDir, RELEASE_FOLDER, VENDOR_FOLDER);
7474

7575
// general
76-
expect(testCase.stdout).toBeTask(['build', 'javascript', 'css']);
76+
expect(testCase.stdout).toBeTask(['release', 'build', 'javascript', 'css']);
7777
expect(testCase.cwd).toHaveExpectedItemsExcept();
7878

7979
// release output

0 commit comments

Comments
 (0)