Skip to content

Commit 99abfa6

Browse files
committed
[Tests] Optimizations; paths now stored centrally.
1 parent cf79bbf commit 99abfa6

File tree

9 files changed

+68
-57
lines changed

9 files changed

+68
-57
lines changed

tests/before.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ function createExampleProject(skip) {
1818

1919
console.log('Trying to setup example project...');
2020

21+
var paths = require('./paths');
2122
var TestProject = require('./helper/project.js');
22-
var tp = new TestProject('/tmp/greppy/');
23+
var tp = new TestProject(paths.exampleProject);
2324
var code;
2425

2526
tp.showOutput = false;

tests/greppy/lib/app/workerTests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
var should = require('should');
88
var path = require('path');
99
var root = path.resolve(__dirname + '/../../../../');
10+
var paths = require(root + '/tests/paths');
1011
var Worker = require(root + '/lib/app/worker');
1112
var wr = null;
1213

@@ -16,7 +17,7 @@ describe.skip('Worker', function() {
1617
var cwdBak = process.cwd();
1718

1819
before(function() {
19-
process.chdir('/tmp/greppy/project/');
20+
process.chdir(paths.exampleProject);
2021
greppy = require(root + '/lib/greppy');
2122
});
2223

tests/greppy/lib/configTests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ var fs = require('fs');
1010
var es = require('execSync');
1111
var extend = require('extend');
1212
var root = path.resolve(__dirname + '/../../../');
13+
var paths = require(root + '/tests/paths');
1314
var Config = require(root + '/lib/config');
1415
var cg = null;
1516

1617
describe('Config', function() {
1718

18-
var configPath = '/tmp/greppy/';
19+
var configPath = paths.temp + '/';
1920
var configFile = 'config.js';
2021
var configMockup = {
2122
propOne: {
@@ -273,7 +274,7 @@ describe('Config', function() {
273274
});
274275

275276
it('should deep-merge a user defined config over the default config if deep is set to true', function() {
276-
277+
277278
var expected = extend(true, {}, defaultMockup, userConfig);
278279

279280
cg = new Config({

tests/greppy/lib/helper/projectTests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
var should = require('should');
88
var path = require('path');
99
var root = path.resolve(__dirname + '/../../../../');
10+
var paths = require(root + '/tests/paths');
1011
var validAppPath = path.resolve('templates/project');
1112
var invalidAppPath = path.resolve('templates');
1213
var Project = require(root + '/lib/helper/project');
@@ -111,7 +112,7 @@ describe('ProjectHelper', function() {
111112
var cwdBak = process.cwd();
112113

113114
beforeEach(function() {
114-
curAppPath = '/tmp/greppy/project/';
115+
curAppPath = paths.exampleProject;
115116

116117
// create contextObject mockup
117118
contextObject = pt.listContexts(curAppPath);

tests/greppy/lib/helper/test/projectTests.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,45 @@
77
var should = require('should');
88
var path = require('path');
99
var fs = require('fs');
10-
var root = path.resolve(__dirname + '/../../../../../');
10+
var root = path.resolve(__dirname + '/../../../../../');
1111
var TestProject = require(root + '/tests/helper/project');
1212
var tp = null;
1313

1414
describe('ProjectHelper for tests', function() {
1515

16-
describe('creating a test project', function() {
17-
this.timeout(0);
16+
this.timeout(0);
1817

19-
it('should have a default path configured', function() {
18+
it('should have a default path configured', function() {
2019

21-
tp = new TestProject();
20+
tp = new TestProject();
2221

23-
tp.path.should.be.a('string');
24-
tp.path.should.match(/\/$/);
25-
});
22+
tp.path.should.be.a('string');
23+
tp.path.should.match(/\/$/);
24+
});
2625

27-
it('should init a default directory if no folder was specified', function(done) {
26+
it('should init a default directory if no folder was specified', function(done) {
2827

29-
tp = new TestProject();
28+
tp = new TestProject();
3029

31-
var path = tp.getTargetPath();
30+
var pPath = tp.getPath();
3231

33-
// somehow, exists only seems to work when called more than once (at least on my system)
34-
// so this needs to be reworked in the future
35-
var result = fs.existsSync(path);
36-
fs.exists(path, function(exists) {
37-
exists.should.be.true;
38-
done();
39-
});
32+
// somehow, exists only seems to work when called more than once (at least on my system)
33+
// so this needs to be reworked in the future
34+
var result = fs.existsSync(pPath);
35+
fs.exists(pPath, function(exists) {
36+
exists.should.be.true;
37+
done();
4038
});
39+
});
4140

42-
it('should create a test-project', function(done) {
41+
it('should create a test-project', function(done) {
4342

44-
tp = new TestProject();
43+
tp = new TestProject();
4544

46-
tp.createProject(function(exitCode) {
47-
exitCode.should.equal(0);
48-
tp.remove();
49-
done();
50-
});
45+
tp.createProject(function(exitCode) {
46+
exitCode.should.equal(0);
47+
tp.remove();
48+
done();
5149
});
5250
});
5351
});

tests/helper/loader/plain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* The plain-loader is responsible for loading test-files
3-
* without special settings
3+
* without special settings.
44
*
55
* @module greppy/helper/test/loader
66
* @author Nabil Krause <nabil.krause@silberlicht.eu>

tests/helper/project.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,33 @@
88
var fs = require('fs');
99
var cp = require('child_process');
1010
var es = require('execSync');
11-
var greppyBinPath = __dirname + '/../../bin/greppy';
11+
var path = require('path');
12+
var root = path.resolve(__dirname + '/../../');
13+
var paths = require(root + '/tests/paths');
14+
var greppyBinPath = root + '/bin/greppy';
1215

1316
/**
1417
* @constructor
18+
*
19+
* @param {String} [path] The path used for creating the project
1520
*/
1621
var Project = function(path)
1722
{
18-
this.path = path || '/tmp/greppy-test/';
19-
this.directoryName = 'project';
23+
this.path = path || paths.temp + '/test-project/';
2024
this.showOutput = false;
2125

2226
// Create the given path
23-
(require('node-fs')).mkdirSync(this.getTargetPath(), '0744', true);
24-
};
25-
26-
/**
27-
* Get the name of the project directory.
28-
*
29-
* @returns {String}
30-
*/
31-
Project.prototype.getDirectoryName = function()
32-
{
33-
return this.directoryName;
27+
(require('node-fs')).mkdirSync(this.getPath(), '0744', true);
3428
};
3529

3630
/**
3731
* Get the builded target path.
3832
*
3933
* @returns {String}
4034
*/
41-
Project.prototype.getTargetPath = function()
35+
Project.prototype.getPath = function()
4236
{
43-
return this.path + this.directoryName + '/';
37+
return path.resolve(this.path) + '/';
4438
};
4539

4640
/**
@@ -50,7 +44,7 @@ Project.prototype.getTargetPath = function()
5044
*/
5145
Project.prototype.exists = function()
5246
{
53-
return fs.existsSync(this.getTargetPath());
47+
return fs.existsSync(this.getPath());
5448
};
5549

5650
/**
@@ -60,7 +54,7 @@ Project.prototype.exists = function()
6054
*/
6155
Project.prototype.remove = function()
6256
{
63-
es.run('rm -rf ' + this.getTargetPath());
57+
es.run('rm -rf ' + this.getPath());
6458
};
6559

6660
/**
@@ -70,8 +64,8 @@ Project.prototype.remove = function()
7064
*/
7165
Project.prototype.clean = function()
7266
{
73-
es.run('rm -rf ' + this.getTargetPath());
74-
es.run('mkdir ' + this.getTargetPath());
67+
es.run('rm -rf ' + this.getPath());
68+
es.run('mkdir ' + this.getPath());
7569
};
7670

7771
/**
@@ -88,7 +82,7 @@ Project.prototype.createProject = function(callback)
8882
}
8983

9084
var ps = cp.spawn(greppyBinPath, ['--new=.'], {
91-
cwd: this.getTargetPath()
85+
cwd: this.getPath()
9286
});
9387

9488
if (this.showOutput) {
@@ -120,7 +114,7 @@ Project.prototype.createProjectSync = function()
120114
var cwd = process.cwd();
121115
var result;
122116

123-
process.chdir(this.getTargetPath());
117+
process.chdir(this.getPath());
124118
result = es[cmd](greppyBinPath + ' --new=.');
125119
result = (cmd === 'run') ? result : result.code;
126120
process.chdir(cwd);

tests/paths.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Relevant paths for tests or their helpers.
3+
*
4+
* @author Nabil Krause <nabil.krause@silberlicht.eu>
5+
*/
6+
7+
var temp = '/tmp/greppy-tests';
8+
var exProject = 'example-project'
9+
10+
var paths = {
11+
temp : temp,
12+
exampleProject : temp + '/' + exProject
13+
};
14+
15+
module.exports = paths;

tests/start.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ var mocha = new Mocha({
1717

1818
var tm = new Manager(mocha, metas, testPath);
1919

20-
//tm.setBefore(execBefore);
21-
//tm.setAfter(execAfter);
22-
//tm.enable('testTests');
23-
//tm.enable('hasTestProject');
20+
tm.setBefore(execBefore);
21+
tm.setAfter(execAfter);
22+
tm.enable('testTests');
23+
tm.enable('hasTestProject');
2424

2525
tm.run();
2626

0 commit comments

Comments
 (0)