From d577cf87aa1cc09ad040b81bbe638f758327304b Mon Sep 17 00:00:00 2001 From: Vittorio Guerriero Date: Sat, 29 Jun 2019 19:49:30 +0100 Subject: [PATCH] feat(log): add test script that will output logs --- config/karma/karma.config.base.js | 5 ++- config/process/process.js | 18 +++++++++++ config/test/webpack.js | 53 ++++++++++++++++--------------- package.json | 1 + 4 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 config/process/process.js diff --git a/config/karma/karma.config.base.js b/config/karma/karma.config.base.js index 435fb4e84..c2f45a778 100644 --- a/config/karma/karma.config.base.js +++ b/config/karma/karma.config.base.js @@ -1,11 +1,14 @@ const webpackConfig = require('../test/webpack.js'); +const ProcessService = require('../process/process'); process.env.CHROME_BIN = require('puppeteer').executablePath(); module.exports = function(config, url) { + const debug = ProcessService(process).getArgument('DEBUG'); + return { basePath: '', frameworks: ['jasmine'], - webpack: webpackConfig, + webpack: webpackConfig(debug), webpackMiddleware: { stats: 'errors-only' }, diff --git a/config/process/process.js b/config/process/process.js new file mode 100644 index 000000000..54f247800 --- /dev/null +++ b/config/process/process.js @@ -0,0 +1,18 @@ +function ProcessService(process) { + const processArguments = process.argv; + + return { + getArgument(argumentName) { + let valueToFind = ''; + processArguments.forEach((argument) => { + const values = argument.split('='); + if (argumentName === values[0]) + valueToFind = values[1]; + }); + + return valueToFind; + } + } +} + +module.exports = ProcessService; diff --git a/config/test/webpack.js b/config/test/webpack.js index c9b51e60d..c1b875f76 100644 --- a/config/test/webpack.js +++ b/config/test/webpack.js @@ -1,34 +1,37 @@ const transformer = require('../../dist/transformer'); const path = require('path'); -const webpack = require('webpack'); -module.exports = { - mode: "development", - resolve: { +module.exports = function(debug) { + return { + mode: "development", + resolve: { extensions: ['.ts', '.js'], - alias: { - ['ts-auto-mock']: path.join(__dirname, '../../dist'), - ['ts-auto-mock/repository']: path.join(__dirname, '../../dist/repository'), - ['ts-auto-mock/extension']: path.join(__dirname, '../../dist/extension'), + alias: { + ['ts-auto-mock']: path.join(__dirname, '../../dist'), + ['ts-auto-mock/repository']: path.join(__dirname, '../../dist/repository'), + ['ts-auto-mock/extension']: path.join(__dirname, '../../dist/extension'), } }, - module: { - rules: [ - { - test: /\.ts$/, - enforce: 'pre', - loader: 'tslint-loader' - }, - { - test: /\.ts$/, - loader: 'awesome-typescript-loader', - options: { - configFileName: "test/tsconfig.json", - getCustomTransformers: (program) => ({ - before: [ transformer.default(program) ] - }) + module: { + rules: [ + { + test: /\.ts$/, + enforce: 'pre', + loader: 'tslint-loader' + }, + { + test: /\.ts$/, + loader: 'awesome-typescript-loader', + options: { + configFileName: "test/tsconfig.json", + getCustomTransformers: (program) => ({ + before: [ transformer.default(program, { + debug: debug ? 'file' : false + }) ] + }) + } } - } - ] + ] + } } }; diff --git a/package.json b/package.json index 348987ad6..57d648658 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "build:extension": "webpack --config config/modules/extension/webpack.js", "build": "npm run build:mock && npm run build:transformer && npm run build:repository && npm run build:extension", "test": "npm run test:transformer && npm run test:framework", + "test:debug": "npm run test:transformer DEBUG=true && npm run test:framework DEBUG=true", "test:transformer": "karma start config/karma/karma.config.transformer.js", "test:framework": "karma start config/karma/karma.config.framework.js", "version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",