refactor: separate out webpacking for tests (#1678)

This commit is contained in:
Nathan Nichols
2021-09-28 16:39:33 -07:00
committed by Mayukha Vadari
parent e65d686cc7
commit 5b9e3dbdc4
4 changed files with 82 additions and 78 deletions

View File

@@ -79,6 +79,7 @@
"build:snippets": "tsc --build ./snippets/tsconfig.json",
"build:lib": "tsc --build tsconfig.build.json",
"build:web": "webpack",
"build:browserTests": "webpack --config ./test/webpack.config.js",
"analyze": "run-s build:web --analyze",
"watch": "run-s build:lib --watch",
"clean": "rm -rf dist",
@@ -86,7 +87,7 @@
"prepublish": "run-s clean build",
"test": "nyc mocha --config=test/.mocharc.json --exit",
"test:integration": "TS_NODE_PROJECT=tsconfig.build.json nyc mocha ./test/integration/**/*.ts ./test/integration/*.ts",
"test:browser": "TS_NODE_PROJECT=tsconfig.build.json nyc mocha ./test/browser/*.ts",
"test:browser": "npm run build:browserTests && TS_NODE_PROJECT=tsconfig.build.json nyc mocha ./test/browser/*.ts",
"test:watch": "TS_NODE_PROJECT=src/tsconfig.json mocha --config=test/.mocharc.json --watch --reporter dot",
"format": "prettier --write '{src,test}/**/*.ts'",
"lint": "eslint . --ext .ts --max-warnings 0",

View File

@@ -17,7 +17,7 @@
mocha.ui('bdd')
</script>
<script src="../testCompiledForWeb/index.js"></script>
<script src="./testCompiledForWeb/index.js"></script>
<script>
mocha.run()

79
test/webpack.config.js Normal file
View File

@@ -0,0 +1,79 @@
'use strict'
const path = require('path')
const webpack = require('webpack')
const assert = require('assert')
function webpackForTest(testFileName) {
const match = testFileName.match(/\/?([^\/]*)\.ts$/)
if (!match) {
assert(false, 'wrong filename:' + testFileName)
}
const test = {
mode: 'production',
cache: true,
externals: [
{
'xrpl-local': 'xrpl',
net: 'null',
},
],
entry: testFileName,
output: {
library: match[1].replace(/-/g, '_'),
path: path.join(__dirname, './testCompiledForWeb/'),
filename: match[1] + '.js',
},
plugins: [
new webpack.ProvidePlugin({ process: 'process/browser' }),
new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
],
module: {
rules: [
{
test: /jayson/,
use: 'null',
},
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
composite: false,
declaration: false,
declarationMap: false,
},
},
},
],
},
],
},
node: {
global: true,
__filename: false,
__dirname: true,
},
resolve: {
alias: {
ws: './dist/npm/client/wsWrapper.js',
'https-proxy-agent': false,
},
extensions: ['.ts', '.js', '.json'],
fallback: {
buffer: require.resolve('buffer/'),
assert: require.resolve('assert/'),
url: require.resolve('url/'),
stream: require.resolve('stream-browserify'),
crypto: require.resolve('crypto-browserify'),
path: require.resolve('path-browserify'),
http: require.resolve('stream-http'),
},
},
}
return test
}
module.exports = [(env, argv) => webpackForTest('./test/integration/index.ts')]

View File

@@ -1,8 +1,6 @@
'use strict'
const path = require('path')
const fs = require('fs')
const webpack = require('webpack')
const assert = require('assert')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
function getDefaultConfiguration() {
@@ -51,79 +49,6 @@ function getDefaultConfiguration() {
}
}
function webpackForTest(testFileName) {
const match = testFileName.match(/\/?([^\/]*)\.ts$/)
if (!match) {
assert(false, 'wrong filename:' + testFileName)
}
const test = {
mode: 'production',
cache: true,
externals: [
{
'xrpl-local': 'xrpl',
net: 'null',
},
],
entry: testFileName,
output: {
library: match[1].replace(/-/g, '_'),
path: path.join(__dirname, './testCompiledForWeb/'),
filename: match[1] + '.js',
},
plugins: [
new webpack.ProvidePlugin({ process: 'process/browser' }),
new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
],
module: {
rules: [
{
test: /jayson/,
use: 'null',
},
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
composite: false,
declaration: false,
declarationMap: false,
},
},
},
],
},
],
},
node: {
global: true,
__filename: false,
__dirname: true,
},
resolve: {
alias: {
ws: './dist/npm/client/wsWrapper.js',
'https-proxy-agent': false,
},
extensions: ['.ts', '.js', '.json'],
fallback: {
buffer: require.resolve('buffer/'),
assert: require.resolve('assert/'),
url: require.resolve('url/'),
stream: require.resolve('stream-browserify'),
crypto: require.resolve('crypto-browserify'),
path: require.resolve('path-browserify'),
http: require.resolve('stream-http'),
},
},
}
return test
}
module.exports = [
(env, argv) => {
const config = getDefaultConfiguration()
@@ -140,5 +65,4 @@ module.exports = [
}
return config
},
(env, argv) => webpackForTest('./test/integration/index.ts'),
]