Skip to content

Commit

Permalink
enhancement(testing): do not bundle node_modules for cypress files
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored and vsavkin committed Jun 27, 2019
1 parent 3b699da commit 889d13f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@cypress/webpack-preprocessor": "~4.1.0",
"tree-kill": "1.2.1",
"ts-loader": "5.3.1",
"tsconfig-paths-webpack-plugin": "3.2.0"
"tsconfig-paths-webpack-plugin": "3.2.0",
"webpack-node-externals": "1.7.2"
}
}
12 changes: 12 additions & 0 deletions packages/cypress/src/plugins/preprocessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('getWebpackConfig', () => {
expect(config.module.rules).toContainEqual({
test: /\.(j|t)sx?$/,
loader: 'ts-loader',
exclude: [/node_modules/],
options: {
configFile: './tsconfig.json',
// https://github.com/TypeStrong/ts-loader/pull/685
Expand Down Expand Up @@ -50,4 +51,15 @@ describe('getWebpackConfig', () => {
'.jsx'
]);
});

it('should keep node_modules external', () => {
const config = getWebpackConfig({
env: {
tsConfig: './tsconfig.json'
}
});
const callback = jest.fn();
config.externals[0](null, '@nestjs/core', callback);
expect(callback).toHaveBeenCalledWith(null, 'commonjs @nestjs/core');
});
});
5 changes: 4 additions & 1 deletion packages/cypress/src/plugins/preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as wp from '@cypress/webpack-preprocessor';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
import * as nodeExternals from 'webpack-node-externals';

export function preprocessTypescript(config: any) {
if (!config.env.tsConfig) {
Expand Down Expand Up @@ -30,13 +31,15 @@ export function getWebpackConfig(config: any) {
{
test: /\.(j|t)sx?$/,
loader: 'ts-loader',
exclude: [/node_modules/],
options: {
configFile: config.env.tsConfig,
// https://github.com/TypeStrong/ts-loader/pull/685
experimentalWatchApi: true
}
}
]
}
},
externals: [nodeExternals()]
};
}

0 comments on commit 889d13f

Please sign in to comment.