Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Can not load webpack. TypeError: arguments[i].apply is not a function. #20

Closed
Pablodotnet opened this issue Mar 31, 2017 · 7 comments
Closed

Comments

@Pablodotnet
Copy link

Hi, I'm trying to use stryker on a project I'm working on, I tried first using it in a simple application that I have to test things like this, and it worked perfectly so I decided to apply it to a bigger project, this bigger project uses Webpack, below I'll paste my three configurations, stryker, karma and webpack and also the error I get.

stryker.conf.js:

module.exports = function(config){
	config.set({
		testRunner: 'karma',
		testFramework: 'jasmine',
		karmaConfigFile: 'karma.conf.js',
		logLevel: 'trace',
		reporter: [
			'progress', 
			'clear-text', 
			'dots', 
			'html', 
			'event-recorder'
		],
		coverageAnalysis: 'perTest',
		plugins: [
			'stryker-jasmine',
			'stryker-karma-runner',
			'stryker-html-reporter'
		]
	});
}

karma.conf.js:

'use strict';

var webpackConfig = require('./webpack/webpack.config.test.js');
require('phantomjs-polyfill');

module.exports = function (config) {
	config.set({
		basePath: '',
		frameworks: ['jasmine'],
		port: 9876,
		colors: true,
		logLevel: config.LOG_INFO,
		autoWatch: false,
		browsers: ['PhantomJS'],
		singleRun: true,
		autoWatchBatchDelay: 300,
		files: [
			'./node_modules/phantomjs-polyfill/bind-polyfill.js',
			'./src/test.index.ts'
		],
		babelPreprocessor: {
			options: {
				presets: ['es2015']
			}
		},
		preprocessors: {
			'src/test.index.ts': ['webpack']
		},
		webpackMiddleware: {
			stats: {
				chunkModules: false,
				colors: true
			}
		},
		webpack: webpackConfig
	});
};

webpack.config.test.js:

var webpack = require('webpack');
var path = require('path');
var loaders = require("./webpack.config.common");
var ExtractTextPlugin = require('extract-text-webpack-plugin');

const ENV = process.env.ENV = process.env.NODE_ENV = 'test';

module.exports = {
	entry: null,
	output: {
		filename: '[name]-[hash].js',
		path: path.resolve(__dirname, '../tmp')
	},
	resolve: {
		modules: [
			path.join(__dirname, "../src"),
			'node_modules'
		],
		extensions: ['.ts', '.js', '.json', '.css', '.scss', '.sass']
	},
	devtool: "source-map-inline",
	plugins: [
		new webpack.ProvidePlugin({
			$: 'jquery',
			jQuery: 'jquery',
			'window.jQuery': 'jquery',
			'window.jquery': 'jquery'
		}),
		new ExtractTextPlugin('[name]-[contenthash].css')
	],
	module: {
		rules: loaders
	}
};

Error Code:

[2017-03-31 11:17:25.727] [TRACE] IsolatedTestRunnerAdapter - 31 03 2017 11:17:25.724:ERROR [preprocess]: Can not load "webpack"!
  TypeError: arguments[i].apply is not a function
  at Compiler.apply (<ProjectPath>/node_modules/tapable/lib/Tapable.js:306:16)
@nicojs
Copy link
Member

nicojs commented Apr 3, 2017

@Pablodotnet thanks for trying out Stryker and reporting this issue.

When you use karmaConfigFile: 'karma.conf.js' as config option, the selected files will be passed through to Stryker. Only those files will be included in the Sandbox, meaning that other files you may include via es6 imports from the index.ts file will not be copied over and cannot be found.

Even if you would copy all files an the initial test run works, mutation testing will not succeed, as we do not support TypeScript as input for now. We are working on this behind the scenes, but you cannot rely on this any time soon.

The only way to make this work for now, is by moving the ts compilation to a pre test step. So compile your ts to js and use those files to run your tests using karma. Once that is working, you should be able to enable Stryker as you're doing right now.

@nicojs
Copy link
Member

nicojs commented Apr 5, 2017

Hmm what setup are you using? Angular 2 with the angular-cli? Or something else?

@unlight
Copy link

unlight commented Apr 20, 2017

Hi guys.
Same issue for me, narrowed down issue to webpack plugins - if any plugin is added - error occurs

@unlight
Copy link

unlight commented Apr 20, 2017

Made some investigation, apply property lost during serialization. (it's defined in prototype)
Force copy apply to own property will not help - gettings error:

SyntaxError: Unexpected token {
    at Object.deserialize (d:\Dev\angular-webpack-seed\node_modules\stryker\src\utils\objectUtils.js:22:44)
    at process.<anonymous> (d:\Dev\angular-webpack-seed\node_modules\stryker\src\isolated-runner\IsolatedTestRunnerAdapterWorker.js:16:41)
    at emitTwo (events.js:106:13)
    at process.emit (events.js:194:7)
    at process.nextTick (internal/child_process.js:766:12)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)

I doubt that serializing helps at all, because content of apply function is:

apply(compiler) {
		const definitions = this.definitions;
		compiler.plugin("compilation", (compilation, params) => {
			compilation.dependencyFactories.set(ConstDependency, new NullFactory());
			compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());

			params.normalModuleFactory.plugin("parser", (parser) => {
				(function walkDefinitions(definitions, prefix) {
					Object.keys(definitions).forEach((key) => {
						const code = definitions[key];
						if(code && typeof code === "object" && !(code instanceof RegExp)) {
							walkDefinitions(code, prefix + key + ".");
							applyObjectDefine(prefix + key, code);
							return;
						}
						applyDefineKey(prefix, key);
						applyDefine(prefix + key, code);
					});
				}(definitions, ""));
....

What is NullFactory, ConstDependency here? It will be undefined.

I think need do load webpack config inside subprocess.

@davidlinse
Copy link

davidlinse commented Aug 15, 2017

Hi, facing the same issue, are there any news on this ?

@Pablodotnet
Copy link
Author

Solved using stryker with the compiled javascript code and not with the typescript code, in this way we are still getting 100% of killed mutants' score.

@gkohen
Copy link

gkohen commented Sep 29, 2017

@Pablodotnet , is there a reason why this issue is closed? It should really be able to run against the transplanted code but still use the source maps to point to the exact location in the original code where things have changed. Considering that Angular 2,4 and the upcoming 5 are all written in TS it would be more than useful to have that capability.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants