Skip to content

Commit 600f1d3

Browse files
author
vdemedes
committed
precompile helpers and fixtures
1 parent e10338e commit 600f1d3

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
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, {
@@ -130,7 +130,22 @@ Api.prototype._setupPrecompiler = function (files) {
130130
this.precompiler = new CachingPrecompiler(cacheDir, this.options.babelConfig, isPowerAssertEnabled);
131131
};
132132

133+
Api.prototype._precompileHelpers = function () {
134+
var self = this;
135+
136+
this._precompiledHelpers = {};
137+
138+
return new AvaFiles({cwd: this.options.resolveTestsFrom})
139+
.findTestDependencies()
140+
.map(function (file) { // eslint-disable-line array-callback-return
141+
var hash = self.precompiler.precompileFile(file);
142+
self._precompiledHelpers[file] = hash;
143+
});
144+
};
145+
133146
Api.prototype._run = function (files, options) {
147+
var self = this;
148+
134149
options = options || {};
135150

136151
var runStatus = new RunStatus({
@@ -150,20 +165,23 @@ Api.prototype._run = function (files, options) {
150165

151166
this._setupPrecompiler(files);
152167

153-
if (this.options.timeout) {
154-
this._setupTimeout(runStatus);
155-
}
168+
return this._precompileHelpers()
169+
.then(function () {
170+
if (self.options.timeout) {
171+
self._setupTimeout(runStatus);
172+
}
156173

157-
var overwatch;
158-
if (this.options.concurrency > 0) {
159-
var concurrency = this.options.serial ? 1 : this.options.concurrency;
160-
overwatch = this._runWithPool(files, runStatus, concurrency);
161-
} else {
162-
// _runWithoutPool exists to preserve legacy behavior, specifically around `.only`
163-
overwatch = this._runWithoutPool(files, runStatus);
164-
}
174+
var overwatch;
175+
if (self.options.concurrency > 0) {
176+
var concurrency = self.options.serial ? 1 : self.options.concurrency;
177+
overwatch = self._runWithPool(files, runStatus, concurrency);
178+
} else {
179+
// _runWithoutPool exists to preserve legacy behavior, specifically around `.only`
180+
overwatch = self._runWithoutPool(files, runStatus);
181+
}
165182

166-
return overwatch;
183+
return overwatch;
184+
});
167185
};
168186

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

0 commit comments

Comments
 (0)