Skip to content

Commit e383c63

Browse files
author
chrisdecoster
committed
add(test) helper methods for temp directories in integration tests. Started to structure the first of the integration tests for tasks in a subfolder. Minor change to package.json and appveyor for the running in the ci.
1 parent 64ded38 commit e383c63

File tree

5 files changed

+99
-11
lines changed

5 files changed

+99
-11
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ install:
2121
- jasmine-node --version
2222

2323
test_script:
24-
- jasmine-node --verbose test
24+
- npm test
2525

2626
build: off

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"es6ify"
1616
],
1717
"scripts": {
18-
"test": "jasmine-node ./test"
18+
"test": "jasmine-node test"
1919
},
2020
"author": "Ben Holloway, Chris Decoster, Brendan Graetz",
2121
"license": "MIT",

test/cli.spec.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
'use strict';
22

3-
var fs = require('fs');
43
var path = require('path');
5-
6-
require('shelljs/global');
7-
84
var helper = require('./helpers/helper');
9-
var testPath = path.join(__dirname, 'test-temp');
105

116
describe('The Angularity global install provides a cli interface.', function () {
127

test/helpers/helper.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
'use strict';
2-
var Q = require('q');
3-
var spawn = require('child_process').spawn;
2+
var Q = require('q'),
3+
path = require('path'),
4+
fs = require('fs'),
5+
rimraf = require('rimraf'),
6+
spawn = require('child_process').spawn;
7+
8+
/**
9+
* Shortcut to a temporary absolute path to perform integration tests.
10+
* @type {*|String}
11+
*/
12+
var testPath = path.resolve(__dirname, '..', 'test-temp');
13+
14+
/**
15+
* Shortcut to create a temporary test path based on name.
16+
* @param folderName
17+
* @returns {*|string}
18+
*/
19+
function resolveTestTempPath(folderName) {
20+
var testTempPath = path.join(testPath, String(folderName));
21+
22+
if (!fs.existsSync(testPath))
23+
fs.mkdirSync(testPath);
24+
25+
if (!fs.existsSync(testTempPath))
26+
fs.mkdirSync(testTempPath);
27+
28+
return testTempPath;
29+
}
30+
31+
/**
32+
* Shortcut to delete all the content of the testPath folder.
33+
*/
34+
function cleanTestTemp() {
35+
rimraf.sync(testPath);
36+
}
437

538
/**
639
* Shortcut to run multiple global angularity commands,
@@ -88,6 +121,9 @@ function runAngularityProcess(args, config) {
88121
}
89122

90123
module.exports = {
91-
runAngularity: runAngularity,
92-
runAngularityAlias: runAngularityAlias
124+
testPath : testPath,
125+
cleanTestTemp : cleanTestTemp,
126+
resolveTestTempPath: resolveTestTempPath,
127+
runAngularity : runAngularity,
128+
runAngularityAlias : runAngularityAlias
93129
};

test/tasks/init.spec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
var fs = require('fs'),
4+
path = require('path');
5+
6+
var helper = require('../helpers/helper');
7+
8+
describe('The Angularity init task should correctly initialise all the files needed for a new project.', function () {
9+
10+
afterEach(function(){
11+
helper.cleanTestTemp();
12+
});
13+
14+
it('should correctly initialise a project with a custom name.', function (done) {
15+
var initTempPath = helper.resolveTestTempPath('init-temp');
16+
process.chdir(initTempPath);
17+
18+
var customName = 'todo';
19+
20+
helper.runAngularity(['init', '-n', customName])
21+
.then(function (result) {
22+
23+
//'init:bower'
24+
var bowerFile = path.join(initTempPath, 'bower.json');
25+
expect(fs.existsSync(bowerFile)).toBe(true);
26+
27+
var bowerFileContent = require(bowerFile);
28+
expect(bowerFileContent.name).toBe(customName);
29+
expect(bowerFileContent.version).toBe('0.0.0');
30+
expect(bowerFileContent.private).toEqual(true);
31+
32+
//'init:npm'
33+
expect(fs.existsSync(path.join(initTempPath, 'package.json'))).toBe(true);
34+
35+
//'init:karma'
36+
expect(fs.existsSync(path.join(initTempPath, 'karma.conf.js'))).toBe(true);
37+
38+
//'init:angularity'
39+
expect(fs.existsSync(path.join(initTempPath, 'angularity.json'))).toBe(true);
40+
41+
//'init:jshint'
42+
expect(fs.existsSync(path.join(initTempPath, '.jshintrc'))).toBe(true);
43+
44+
//'init:gitignore'
45+
expect(fs.existsSync(path.join(initTempPath, '.gitignore'))).toBe(true);
46+
47+
//'init:composition'
48+
var appPath = path.join(initTempPath, 'app');
49+
expect(fs.existsSync(path.join(appPath, 'index.html'))).toBe(true);
50+
expect(fs.existsSync(path.join(appPath, 'index.js'))).toBe(true);
51+
expect(fs.existsSync(path.join(appPath, 'index.scss'))).toBe(true);
52+
53+
done();
54+
});
55+
});
56+
57+
});

0 commit comments

Comments
 (0)