Skip to content

Commit

Permalink
Merge pull request #57 from homer0/homer0_ts
Browse files Browse the repository at this point in the history
TypeScript support
  • Loading branch information
homer0 committed Feb 9, 2019
2 parents b0e3297 + 962624d commit 3176e2d
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/services/configurations/baseConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class WebpackBaseConfiguration extends ConfigurationFile {
const { rules } = this.webpackRulesConfiguration.getConfig(params);
const config = {
resolve: {
extensions: ['.js', '.jsx'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: ['./', 'node_modules'],
},
module: {
Expand Down
5 changes: 5 additions & 0 deletions src/services/configurations/nodeDevelopmentConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class WebpackNodeDevelopmentConfiguration extends ConfigurationFile {
},
mode: 'development',
};
// If the target has source maps enabled...
if (target.sourceMap.development) {
// ...configure the devtool
config.devtool = 'source-map';
}
// Reduce the configuration.
return this.events.reduce(
[
Expand Down
5 changes: 5 additions & 0 deletions src/services/configurations/nodeProductionConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class WebpackNodeProductionConfiguration extends ConfigurationFile {
mode: 'production',
watch: target.watch.production,
};
// If the target has source maps enabled...
if (target.sourceMap.production) {
// ...configure the devtool
config.devtool = 'source-map';
}
// Reduce the configuration.
return this.events.reduce(
[
Expand Down
8 changes: 4 additions & 4 deletions tests/services/configurations/baseConfiguration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('services/configurations:baseConfiguration', () => {
};
const expectedConfig = {
resolve: {
extensions: ['.js', '.jsx'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: ['./', 'node_modules'],
},
module: {
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('services/configurations:baseConfiguration', () => {
};
const expectedConfig = {
resolve: {
extensions: ['.js', '.jsx'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: ['./', 'node_modules'],
},
module: {
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('services/configurations:baseConfiguration', () => {
};
const expectedConfig = {
resolve: {
extensions: ['.js', '.jsx'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: ['./', 'node_modules'],
},
module: {
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('services/configurations:baseConfiguration', () => {
const params = { target };
const expectedConfig = {
resolve: {
extensions: ['.js', '.jsx'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: ['./', 'node_modules'],
},
module: {
Expand Down
92 changes: 92 additions & 0 deletions tests/services/configurations/nodeDevelopmentConfiguration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,91 @@ describe('services/configurations:nodeDevelopmentConfiguration', () => {
watch: {
development: false,
},
sourceMap: {
development: false,
},
};
const entry = {
[target.name]: ['index.js'],
};
const output = {
js: 'statics/js/build.js',
jsChunks: 'statics/js/build.[name].js',
};
const copy = ['file-to-copy'];
const params = {
target,
entry,
output,
copy,
};
const expectedConfig = {
entry,
output: {
path: `./${target.folders.build}`,
filename: output.js,
chunkFilename: output.jsChunks,
publicPath: '/',
},
watch: target.watch.development,
mode: 'development',
plugins: expect.any(Array),
target: 'node',
node: {
__dirname: false,
},
};
let sut = null;
let result = null;
// When
sut = new WebpackNodeDevelopmentConfiguration(
appLogger,
events,
pathUtils,
webpackBaseConfiguration
);
result = sut.getConfig(params);
// Then
expect(result).toEqual(expectedConfig);
expect(webpackMock.NoEmitOnErrorsPluginMock).toHaveBeenCalledTimes(1);
expect(OptimizeCssAssetsPlugin).toHaveBeenCalledTimes(1);
expect(CopyWebpackPlugin).toHaveBeenCalledTimes(1);
expect(CopyWebpackPlugin).toHaveBeenCalledWith(copy);
expect(ProjextWebpackBundleRunner).toHaveBeenCalledTimes(0);
expect(events.reduce).toHaveBeenCalledTimes(1);
expect(events.reduce).toHaveBeenCalledWith(
[
'webpack-node-development-configuration',
'webpack-node-configuration',
],
expectedConfig,
params
);
});

it('should create a configuration and enable source maps', () => {
// Given
const appLogger = 'appLogger';
const events = {
reduce: jest.fn((eventName, loaders) => loaders),
};
const pathUtils = 'pathUtils';
const webpackBaseConfiguration = 'webpackBaseConfiguration';
const target = {
name: 'targetName',
folders: {
build: 'build-folder',
},
paths: {
source: 'source-path',
},
excludeModules: [],
watch: {
development: false,
},
sourceMap: {
development: true,
},
};
const entry = {
[target.name]: ['index.js'],
Expand Down Expand Up @@ -108,6 +193,7 @@ describe('services/configurations:nodeDevelopmentConfiguration', () => {
node: {
__dirname: false,
},
devtool: 'source-map',
};
let sut = null;
let result = null;
Expand Down Expand Up @@ -161,6 +247,9 @@ describe('services/configurations:nodeDevelopmentConfiguration', () => {
inspect: {
enabled: false,
},
sourceMap: {
development: false,
},
};
const entry = {
[target.name]: ['index.js'],
Expand Down Expand Up @@ -245,6 +334,9 @@ describe('services/configurations:nodeDevelopmentConfiguration', () => {
watch: {
development: true,
},
sourceMap: {
development: false,
},
};
const entry = {
[target.name]: ['index.js'],
Expand Down
80 changes: 80 additions & 0 deletions tests/services/configurations/nodeProductionConfiguration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,85 @@ describe('services/configurations:nodeProductionConfiguration', () => {
watch: {
production: false,
},
sourceMap: {
production: false,
},
};
const entry = {
[target.name]: ['index.js'],
};
const output = {
js: 'statics/js/build.js',
jsChunks: 'statics/js/build.[name].js',
};
const copy = ['file-to-copy'];
const params = {
target,
entry,
output,
copy,
};
const expectedConfig = {
entry,
output: {
path: `./${target.folders.build}`,
filename: output.js,
chunkFilename: output.jsChunks,
publicPath: '/',
},
mode: 'production',
plugins: expect.any(Array),
target: 'node',
node: {
__dirname: false,
},
watch: target.watch.production,
};
let sut = null;
let result = null;
// When
sut = new WebpackNodeProductionConfiguration(
events,
pathUtils,
webpackBaseConfiguration
);
result = sut.getConfig(params);
// Then
expect(result).toEqual(expectedConfig);
expect(webpackMock.NoEmitOnErrorsPluginMock).toHaveBeenCalledTimes(1);
expect(OptimizeCssAssetsPlugin).toHaveBeenCalledTimes(1);
expect(CopyWebpackPlugin).toHaveBeenCalledTimes(1);
expect(CopyWebpackPlugin).toHaveBeenCalledWith(copy);
expect(events.reduce).toHaveBeenCalledTimes(1);
expect(events.reduce).toHaveBeenCalledWith(
[
'webpack-node-production-configuration',
'webpack-node-configuration',
],
expectedConfig,
params
);
});

it('should create a configuration and enable source maps', () => {
// Given
const events = {
reduce: jest.fn((eventName, loaders) => loaders),
};
const pathUtils = 'pathUtils';
const webpackBaseConfiguration = 'webpackBaseConfiguration';
const target = {
name: 'targetName',
folders: {
build: 'build-folder',
},
excludeModules: [],
watch: {
production: false,
},
sourceMap: {
production: true,
},
};
const entry = {
[target.name]: ['index.js'],
Expand Down Expand Up @@ -99,6 +178,7 @@ describe('services/configurations:nodeProductionConfiguration', () => {
__dirname: false,
},
watch: target.watch.production,
devtool: 'source-map',
};
let sut = null;
let result = null;
Expand Down

0 comments on commit 3176e2d

Please sign in to comment.