Closed dbigintonpro closed 5 years ago
Can you please provide us with your wallaby configuration file?
Absolutely, see below
WallabyTest.ts
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
Wallaby.js
var wallabyWebpack = require('wallaby-webpack');
var path = require('path');
var compilerOptions = Object.assign(
require('./tsconfig.json').compilerOptions,
// require('./apps/**/tsconfig.spec.json').compilerOptions,
require('./libs/core/tsconfig.spec.json').compilerOptions
);
module.exports = function(wallaby) {
var webpackPostprocessor = wallabyWebpack({
entryPatterns: ['wallabyTest.js', 'apps/**/*spec.js', 'libs/**/*spec.js'],
emitModulePaths: true,
module: {
rules: [
{ test: /\.css$/, loader: ['raw-loader', 'css-loader'] },
{ test: /\.html$/, loader: 'raw-loader' },
{
test: /\.ts$/,
loader: '@ngtools/webpack',
include: /node_modules/,
query: { tsConfigPath: 'tsconfig.json' }
},
{
test: /\.js$/,
loader: 'angular2-template-loader',
exclude: /node_modules/
},
{ test: /\.js$/, loader: 'shebang-loader', include: /node_modules/ },
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.styl$/, loaders: ['raw-loader', 'stylus-loader'] },
{ test: /\.less$/, loaders: ['raw-loader', 'less-loader'] },
{ test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'sass-loader'] },
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000' }
]
},
resolve: {
extensions: ['.js', '.ts'],
modules: [
path.join(wallaby.projectCacheDir, 'apps'),
path.join(wallaby.projectCacheDir, 'libs'),
'node_modules'
],
alias: {
'@lazard/core': path.join(
wallaby.projectCacheDir,
'libs/core/src/index.ts'
)
}
},
node: {
fs: 'empty',
net: 'empty',
tls: 'empty',
dns: 'empty'
}
});
return {
files: [
{ pattern: 'wallabyTest.ts', load: false },
{
pattern: 'apps/**/*.+(ts|css|less|scss|sass|styl|html|json|svg)',
load: false
},
{ pattern: 'apps/**/*.d.ts', ignore: true },
{ pattern: 'apps/**/*spec.ts', ignore: true },
{
pattern: 'libs/**/*.+(ts|css|less|scss|sass|styl|html|json|svg)',
load: false
},
{ pattern: 'libs/**/*.d.ts', ignore: true },
{ pattern: 'libs/**/*spec.ts', ignore: true },
{ pattern: 'apps/**/*-e2e/**', ignore: true },
{ pattern: 'libs/**/*-e2e/**', ignore: true }
],
tests: [
{ pattern: 'apps/**/*spec.ts', load: false },
{ pattern: 'libs/**/*spec.ts', load: false },
{ pattern: 'apps/**/*-e2e/**', ignore: true },
{ pattern: 'libs/**/*-e2e/**', ignore: true }
],
testFramework: 'jasmine',
compilers: {
'**/*.ts': wallaby.compilers.typeScript(compilerOptions)
},
env: {
kind: 'electron'
},
postprocessor: webpackPostprocessor,
workers: {initial: 1, regular: 1},
debug: true,
setup: function() {
window.__moduleBundler.loadTests();
}
};
};
It seems that all the imports define in WallabyTest.ts cannot be found, for example, if i comment out the first, and attempt to run, the error is reproduced with the first uncommented import.
OK, partly a mistake by me, I was referencing WallabyTest.js but had my file named as WallabyTest.ts. This is now corrected to WallabyTest.js and the imports are no longer failing, except I now have an error relating to protractor, as shown below:
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:middleware Preparing to serve /jasmine@2.1.3/starter.js
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:middleware Serving /jasmine@2.1.3/starter.js from disk
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:workers Sandbox (active) [t63h9] error: Uncaught Error: Cannot find module 'protractor'
[Error] Runtime error: Uncaught Error: Cannot find module 'protractor'
[Error] at http://localhost:62920/____wallaby-bundle.js?1548116718726&wallabyFileId=bundle:320
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:workers [t63h9] Loaded 0 test(s)
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:workers [t63h9] Run 0 test(s), skipped 0 test(s)
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:workers [t63h9] Sandbox is responsive, closing it
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Test run finished
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Processed console.log entries
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Processed loading sequences
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Processed executed tests
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Processed code coverage
[Info] Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Test run result processed and sent to IDE
Any thoughts?
It looks like some of your e2e tests are still being included in either your files
section or your tests
section. Take a look at which of your files are referencing protractor
and make sure that they're not being included by your files or tests patterns.
Thanks. I've made some adjustments to the wallaby.js config file:
Protractor is no longer in error. I now receive the following:
[Error] Postprocessor run failure: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
[Error] - configuration.entry should be one of these:
[Error] function | object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string]
[Error] -> The entry point(s) of the compilation.
[Error] Details:
[Error] * configuration.entry should be an instance of function
[Error] -> A Function returning an entry object, an entry string, an entry array or a promise to these things.
[Error] * configuration.entry should not be empty.
[Error] -> Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.
[Error] * configuration.entry should be a string.
[Error] -> An entry point without name. The string is resolved to a module which is loaded upon startup.
[Error] * configuration.entry should be an array:
[Error] [non-empty string]
Update wallaby.js config file:
var wallabyWebpack = require('wallaby-webpack');
var path = require('path');
var compilerOptions = Object.assign(
require('./tsconfig.json').compilerOptions,
// require('./apps/**/tsconfig.spec.json').compilerOptions,
require('./libs/core/tsconfig.spec.json').compilerOptions
);
var patterns = [
'apps/*/src/**/*spec.ts', 'libs/*/src/**/*spec.ts', // run all tests
// 'apps/app1/src/**/*spec.js', // run test just for app1
// 'libs/lib2/src/**/*spec.js', // run test just for lib2
];
module.exports = function(wallaby) {
var webpackPostprocessor = wallabyWebpack({
entryPatterns: [ 'wallabyTest.js', ...patterns ],
emitModulePaths: true,
module: {
rules: [
{ test: /\.css$/, loader: ['raw-loader', 'css-loader'] },
{ test: /\.html$/, loader: 'raw-loader' },
{
test: /\.ts$/,
loader: '@ngtools/webpack',
include: /node_modules/,
query: { tsConfigPath: 'tsconfig.json' }
},
{
test: /\.js$/,
loader: 'angular2-template-loader',
exclude: /node_modules/
},
{ test: /\.js$/, loader: 'shebang-loader', include: /node_modules/ },
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.styl$/, loaders: ['raw-loader', 'stylus-loader'] },
{ test: /\.less$/, loaders: ['raw-loader', 'less-loader'] },
{ test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'sass-loader'] },
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000' }
]
},
resolve: {
extensions: ['.js', '.ts'],
modules: [
path.join(wallaby.projectCacheDir, 'apps'),
path.join(wallaby.projectCacheDir, 'libs'),
'node_modules'
],
alias: {
'@lazard/core': path.join(
wallaby.projectCacheDir,
'libs/core/src/index.ts'
)
}
},
node: {
fs: 'empty',
net: 'empty',
tls: 'empty',
dns: 'empty'
}
});
return {
files: [
{ pattern: 'wallabyTest.ts', load: false },
{ pattern: 'apps/**/*.+(ts|css|less|scss|sass|styl|html|json|svg)', load: false },
{ pattern: 'apps/**/*.d.ts', ignore: true },
// { pattern: 'apps/**/*spec.ts', ignore: true },
{ pattern: 'apps/*/src/**/*.spec.ts', ignore: true },
{ pattern: 'libs/**/*.+(ts|css|less|scss|sass|styl|html|json|svg)', load: false },
{ pattern: 'libs/**/*.d.ts', ignore: true },
// { pattern: 'libs/**/*spec.ts', ignore: true },
{ pattern: 'libs/*/src/**/*.spec.ts', ignore: true },
],
tests: [
// { pattern: 'apps/**/*.spec.ts', load: false },
{ pattern: 'apps/*/src/**/*.spec.ts', load: false },
// { pattern: 'apps/**/e2e/**', ignore: true },
// { pattern: 'libs/**/*.spec.ts', load: false },
{ pattern: 'libs/*/src/**/*.spec.ts', load: false },
// { pattern: 'libs/**/e2e/**', ignore: true },
],
testFramework: 'jasmine',
compilers: {
'**/*.ts': wallaby.compilers.typeScript(compilerOptions)
},
env: {
kind: 'electron'
},
postprocessor: webpackPostprocessor,
workers: {initial: 1, regular: 1},
debug: true,
setup: function() {
window.__moduleBundler.loadTests();
}
};
};
It looks like your entryPatterns
in the webpack config are using .ts
file extension, but are supposed to be using .js
extension as in your previous config version.
Also your tests
patterns: apps/*/src/**/*.spec.ts
and libs/*/src/**/*.spec.ts
may not be correct (ie. not finding any files). Please double check them as well.
Thanks @ArtemGovorov & @smcenlly,
Your prompts have pointed me in the right direction and I have managed to get the testing with Wallaby to work.
Thanks again
Awesome, thanks for the update!
I am currently reviewing the rollout of WallabyJS for a number of applications however, I am having trouble getting it to work.
It should be noted that I am running in an Angular 7 NX workspace with multiple apps and libs.
Code editor or IDE name and version
Visual Studio Code v1.30.2
OS name and version
Windows 10
Wallaby.js configuration file
The errors received when running the wallaby.js configuration file are below.
These are the only 2 errors received.
Below are the dependencies from package.json
Your help would be greatly appreciated.