Skip to content

Instantly share code, notes, and snippets.

@ArtemGovorov
Last active June 28, 2017 06:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ArtemGovorov/2d5a6535316afa7ff12e0295d2c2f7d5 to your computer and use it in GitHub Desktop.
Save ArtemGovorov/2d5a6535316afa7ff12e0295d2c2f7d5 to your computer and use it in GitHub Desktop.
Wallaby.js config for ng-cli generated project. The config file needs to be in the project root. Works faster with Electron runner: https://wallabyjs.com/docs/integration/electron.html
module.exports = function (wallaby) {
const compilerOptions = require('./src/tsconfig.json').compilerOptions;
compilerOptions.noEmitOnError = false;
return {
files: [
{pattern: 'node_modules/es6-shim/es6-shim.js', instrument: false},
{pattern: 'node_modules/systemjs/dist/system-polyfills.js', instrument: false},
{pattern: 'node_modules/reflect-metadata/Reflect.js', instrument: false},
{pattern: 'node_modules/systemjs/dist/system.js', instrument: false},
{pattern: 'node_modules/rxjs/bundles/Rx.js', instrument: false},
{pattern: 'node_modules/zone.js/dist/zone.js', instrument: false},
{pattern: 'node_modules/zone.js/dist/async-test.js', instrument: false},
{pattern: 'src/system-config.ts', instrument: false},
{pattern: 'src/app/**/*.ts', load: false},
{pattern: 'src/app/**/*.html', load: false},
{pattern: 'src/app/**/*.css', load: false},
{pattern: 'src/app/**/*.spec.ts', ignore: true}
],
tests: [{pattern: 'src/app/**/*.spec.ts', load: false}],
preprocessors: {
// see https://github.com/wallabyjs/public/issues/632#issuecomment-224205605
'src/system-config.ts': file => file.content
.replace(/vendor/g, 'node_modules')
.replace(/app\//g, 'src\/app\/')
},
compilers: {
'**/*.ts': wallaby.compilers.typeScript(compilerOptions)
},
middleware: function (app, express) {
app.use('/node_modules', express.static(require('path').join(__dirname, 'node_modules')));
},
setup: function (wallaby) {
wallaby.delayStart();
System.config({
defaultJSExtensions: true
});
var promises = [];
Promise.all([System.import('@angular/core/testing'), System.import('@angular/platform-browser-dynamic/testing')])
.then(function (results) {
var testing = results[0];
var browser = results[1];
testing.setBaseTestProviders(
browser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
browser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
);
for (var i = 0, len = wallaby.tests.length; i < len; i++) {
promises.push(System['import'](wallaby.tests[i].replace(/\.js$/, '')));
}
})
.then(function () {
return Promise.all(promises);
})
.then(function () {
wallaby.start();
})
.catch(function (e) {
setTimeout(function () {
throw e;
}, 0);
});
},
debug: true
};
};
@zpydee
Copy link

zpydee commented May 17, 2016

Tried pushing up to a branch for a PR, but have no access.
Consider adding:
{pattern: 'src/app/**/*.css', load: false},
and change
tests: [{pattern: 'src/app/*.spec.ts', load: false}], to tests: [{pattern: 'src/app/**/*.spec.ts', load: false}],

@ArtemGovorov
Copy link
Author

Thanks, edited the config.

@danimbrogno
Copy link

Tried this out but received error that System was undefined. I installed system-js, and now I see error:

Uncaught Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:49200/@angular/core/testing.js
    Error: XHR error (404 Not Found) loading http://localhost:49200/@angular/core/testing.js
        at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:49200/node_modules/zone.js/dist/zone.js?1474390371804&wallabyFileId=5:647:29)
        at ZoneDelegate.invokeTask (http://localhost:49200/node_modules/zone.js/dist/zone.js?1474390371804&wallabyFileId=5:236:37)
        at Zone.runTask (http://localhost:49200/node_modules/zone.js/dist/zone.js?1474390371804&wallabyFileId=5:136:47)
        at XMLHttpRequest.ZoneTask.invoke (http://localhost:49200/node_modules/zone.js/dist/zone.js?1474390371804&wallabyFileId=5:304:33)
    Error loading http://localhost:49200/@angular/core/testing.js

Any advice?

@danimbrogno
Copy link

Just noticed the file "src/system-config.ts" is missing. How is this generated?

@danimbrogno
Copy link

Ahh, guessing this config is for the version of angular2-cli before it switched over to webpack builds. Any chance you have a config for angular2-cli + webpack?

@danimbrogno
Copy link

nevermind! Just discovered the example config here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment