Skip to content

Commit 9ec8879

Browse files
committed
chore(transformer): Use the tsconfig.playground.json config for Webpack playground builds
1 parent c0fab42 commit 9ec8879

File tree

4 files changed

+86
-71
lines changed

4 files changed

+86
-71
lines changed

config/karma/karma.config.base.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,42 @@ const webpackConfig = require('../test/webpack.js');
22
const ProcessService = require('../../utils/process/process');
33
process.env.CHROME_BIN = require('puppeteer').executablePath();
44

5-
module.exports = function(config, url) {
6-
const processService = ProcessService(process);
7-
const debug = processService.getArgument('DEBUG');
8-
const disableCache = processService.getArgument('DISABLECACHE');
5+
module.exports = function(config, url, typescriptConfig) {
6+
const processService = ProcessService(process);
7+
const debug = processService.getArgument('DEBUG');
8+
const disableCache = processService.getArgument('DISABLECACHE');
99

10-
return {
11-
basePath: '',
12-
frameworks: ['jasmine'],
13-
webpack: webpackConfig(debug, disableCache),
14-
webpackMiddleware: {
15-
stats: 'errors-only'
16-
},
17-
files: [
18-
{
19-
pattern: url,
20-
watched: false
21-
}
22-
],
23-
preprocessors: {
24-
[url]: ['webpack']
25-
},
26-
webpackServer: {
27-
noInfo: true
28-
},
29-
reporters: ['progress'],
30-
port: 9876,
31-
colors: true,
32-
logLevel: config.LOG_INFO,
33-
autoWatch: true,
34-
customLaunchers: {
35-
Chrome_no_sandbox: {
36-
base: 'Chrome',
37-
flags: ['--headless', '--no-sandbox']
38-
}
39-
},
40-
browsers: ['ChromeHeadless'],
41-
singleRun: true
42-
}
10+
return {
11+
basePath: '',
12+
frameworks: ['jasmine'],
13+
webpack: webpackConfig({ typescriptConfig, debug, disableCache }),
14+
webpackMiddleware: {
15+
stats: 'errors-only'
16+
},
17+
files: [
18+
{
19+
pattern: url,
20+
watched: false
21+
}
22+
],
23+
preprocessors: {
24+
[url]: ['webpack']
25+
},
26+
webpackServer: {
27+
noInfo: true
28+
},
29+
reporters: ['progress'],
30+
port: 9876,
31+
colors: true,
32+
logLevel: config.LOG_INFO,
33+
autoWatch: true,
34+
customLaunchers: {
35+
Chrome_no_sandbox: {
36+
base: 'Chrome',
37+
flags: ['--headless', '--no-sandbox']
38+
}
39+
},
40+
browsers: ['ChromeHeadless'],
41+
singleRun: true
42+
}
4343
};
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
const typescriptConfig = require('../../tsconfig.playground.json');
12
const karmaBaseConfig = require('./karma.config.base');
23

34
module.exports = function(config) {
4-
const karmaConfig = karmaBaseConfig(config, '../../test/playground/**/*.test.js');
5+
const karmaConfig = karmaBaseConfig(config, '../../test/playground/**/*.test.js', typescriptConfig);
56

6-
config.set(karmaConfig);
7+
config.set(karmaConfig);
78
};
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
const typescriptConfig = require('../../tsconfig.playground.json');
12
const karmaBaseConfig = require('./karma.config.base');
23

34
module.exports = function(config) {
4-
const karmaConfig = karmaBaseConfig(config, '../../test/playground/**/*.test.ts');
5+
const karmaConfig = karmaBaseConfig(config, '../../test/playground/**/*.test.ts', typescriptConfig);
56

6-
config.set(karmaConfig);
7+
config.set(karmaConfig);
78
};

config/test/webpack.js

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
11
const transformer = require('../../dist/transformer');
22
const path = require('path');
33

4-
module.exports = function (debug, disableCache) {
5-
return {
6-
mode: "development",
7-
resolve: {
8-
extensions: ['.ts', '.js'],
9-
alias: {
10-
['ts-auto-mock']: path.join(__dirname, '../../dist'),
11-
['ts-auto-mock/repository']: path.join(__dirname, '../../dist/repository'),
12-
['ts-auto-mock/extension']: path.join(__dirname, '../../dist/extension'),
13-
}
4+
module.exports = function ({ typescriptConfig, debug, disableCache }) {
5+
const defaultOptions = {
6+
debug: false,
7+
cacheBetweenTests: true,
8+
};
9+
10+
const {
11+
compilerOptions: {
12+
plugins = [],
13+
}
14+
} = typescriptConfig || { compilerOptions: {} };
15+
const [{ transform, ...transformOptions } = defaultOptions] = plugins;
16+
17+
return {
18+
mode: "development",
19+
resolve: {
20+
extensions: ['.ts', '.js'],
21+
alias: {
22+
['ts-auto-mock']: path.join(__dirname, '../../dist'),
23+
['ts-auto-mock/repository']: path.join(__dirname, '../../dist/repository'),
24+
['ts-auto-mock/extension']: path.join(__dirname, '../../dist/extension'),
25+
}
26+
},
27+
module: {
28+
rules: [
29+
{
30+
test: /\.ts$/,
31+
enforce: 'pre',
32+
loader: 'eslint-loader'
1433
},
15-
module: {
16-
rules: [
17-
{
18-
test: /\.ts$/,
19-
enforce: 'pre',
20-
loader: 'eslint-loader'
21-
},
22-
{
23-
test: /\.ts$/,
24-
loader: 'awesome-typescript-loader',
25-
options: {
26-
getCustomTransformers: (program) => ({
27-
before: [transformer.default(program, {
28-
debug: debug ? debug : false,
29-
cacheBetweenTests: disableCache !== 'true'
30-
})]
31-
})
32-
}
33-
}
34-
]
34+
{
35+
test: /\.ts$/,
36+
loader: 'awesome-typescript-loader',
37+
options: {
38+
getCustomTransformers: (program) => ({
39+
before: [transformer.default(program, {
40+
...transformOptions,
41+
debug: debug || transformOptions.debug,
42+
cacheBetweenTests: disableCache ? disableCache !== 'true' : transformOptions.cacheBetweenTests,
43+
})],
44+
})
45+
}
3546
}
47+
]
3648
}
49+
};
3750
};

0 commit comments

Comments
 (0)