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

@@ -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')]