Skip to content

Commit 187b0a6

Browse files
author
vdemedes
committed
precompile helpers and fixtures
1 parent 415cd2f commit 187b0a6

File tree

5 files changed

+63
-15
lines changed

5 files changed

+63
-15
lines changed

api.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = Api;
6666

6767
Api.prototype._runFile = function (file, runStatus, execArgv) {
6868
var hash = this.precompiler.precompileFile(file);
69-
var precompiled = {};
69+
var precompiled = objectAssign({}, this._precompiledHelpers);
7070
precompiled[file] = hash;
7171

7272
var options = objectAssign({}, this.options, {
@@ -137,7 +137,22 @@ Api.prototype._setupPrecompiler = function (files) {
137137
});
138138
};
139139

140+
Api.prototype._precompileHelpers = function () {
141+
var self = this;
142+
143+
this._precompiledHelpers = {};
144+
145+
return new AvaFiles({cwd: this.options.resolveTestsFrom})
146+
.findTestHelpers()
147+
.map(function (file) { // eslint-disable-line array-callback-return
148+
var hash = self.precompiler.precompileFile(file);
149+
self._precompiledHelpers[file] = hash;
150+
});
151+
};
152+
140153
Api.prototype._run = function (files, options) {
154+
var self = this;
155+
141156
options = options || {};
142157

143158
var runStatus = new RunStatus({
@@ -157,20 +172,23 @@ Api.prototype._run = function (files, options) {
157172

158173
this._setupPrecompiler(files);
159174

160-
if (this.options.timeout) {
161-
this._setupTimeout(runStatus);
162-
}
175+
return this._precompileHelpers()
176+
.then(function () {
177+
if (self.options.timeout) {
178+
self._setupTimeout(runStatus);
179+
}
163180

164-
var overwatch;
165-
if (this.options.concurrency > 0) {
166-
var concurrency = this.options.serial ? 1 : this.options.concurrency;
167-
overwatch = this._runWithPool(files, runStatus, concurrency);
168-
} else {
169-
// _runWithoutPool exists to preserve legacy behavior, specifically around `.only`
170-
overwatch = this._runWithoutPool(files, runStatus);
171-
}
181+
var overwatch;
182+
if (self.options.concurrency > 0) {
183+
var concurrency = self.options.serial ? 1 : self.options.concurrency;
184+
overwatch = self._runWithPool(files, runStatus, concurrency);
185+
} else {
186+
// _runWithoutPool exists to preserve legacy behavior, specifically around `.only`
187+
overwatch = self._runWithoutPool(files, runStatus);
188+
}
172189

173-
return overwatch;
190+
return overwatch;
191+
});
174192
};
175193

176194
Api.prototype._computeForkExecArgs = function (files) {

test/api.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ function generateTests(prefix, apiCreator) {
7676
});
7777
});
7878

79+
test(prefix + 'precompile helpers', function (t) {
80+
t.plan(1);
81+
82+
var api = apiCreator();
83+
84+
return api.run([path.join(__dirname, 'fixture/precompile-helpers/test/test.js')])
85+
.then(function (result) {
86+
t.is(result.passCount, 1);
87+
});
88+
});
89+
7990
test(prefix + 'generators support', function (t) {
8091
t.plan(1);
8192

@@ -697,7 +708,10 @@ function generateTests(prefix, apiCreator) {
697708
test(prefix + 'caching is enabled by default', function (t) {
698709
t.plan(3);
699710
rimraf.sync(path.join(__dirname, 'fixture/caching/node_modules'));
700-
var api = apiCreator();
711+
712+
var api = apiCreator({
713+
resolveTestsFrom: path.join(__dirname, 'fixture/caching')
714+
});
701715

702716
return api.run([path.join(__dirname, 'fixture/caching/test.js')])
703717
.then(function () {
@@ -720,7 +734,11 @@ function generateTests(prefix, apiCreator) {
720734
test(prefix + 'caching can be disabled', function (t) {
721735
t.plan(1);
722736
rimraf.sync(path.join(__dirname, 'fixture/caching/node_modules'));
723-
var api = apiCreator({cacheEnabled: false});
737+
738+
var api = apiCreator({
739+
resolveTestsFrom: path.join(__dirname, 'fixture/caching'),
740+
cacheEnabled: false
741+
});
724742

725743
return api.run([path.join(__dirname, 'fixture/caching/test.js')])
726744
.then(function () {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default async function () {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default async function () {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import test from '../../../../';
2+
import a from './helpers/a';
3+
import b from './_b';
4+
5+
test(async t => {
6+
await a();
7+
await b();
8+
9+
t.pass();
10+
});

0 commit comments

Comments
 (0)