test: run address-codec tests in the browser (#2466)

Update tests to use jasmine compatible functions.

This means changing `test` to `it`, `toStrictEqual` to `toEqual` (which
is still strict), `toThrowError` to `toError`, and updating the param
for toError to pass an `Error` object.

Remove the need to specify --single-run.
This commit is contained in:
Caleb Kniffen
2023-09-19 14:57:34 -05:00
parent 83870acbfb
commit c143dc3e99
15 changed files with 213 additions and 235 deletions

View File

@@ -1,39 +1,14 @@
const webpackConfig = require('./test/webpack.config')[0]()
const baseKarmaConfig = require('../../karma.config')
const webpackConfig = require('./test/webpack.config')
delete webpackConfig.entry
module.exports = function (config) {
config.set({
plugins: ['karma-webpack', 'karma-jasmine', 'karma-chrome-launcher'],
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
webpack: webpackConfig,
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: ['build/xrpl-latest.js', 'test/integration/**/*.test.ts'],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
// Use webpack to bundle our test files
'test/integration/**/*.test.ts': ['webpack'],
},
browsers: ['ChromeHeadless'],
// runs only one browser at a time
concurrency: 1,
// CI mode
singleRun: true,
client: {
jasmine: {
// ensures that tests are run in order instead of a random order
random: false,
},
},
})
baseKarmaConfig(config)
}

View File

@@ -61,7 +61,7 @@
"prepublish": "run-s clean build",
"test": "jest --config=jest.config.unit.js --verbose false --silent=false",
"test:integration": "TS_NODE_PROJECT=tsconfig.build.json jest --config=jest.config.integration.js --verbose false --silent=false --runInBand",
"test:browser": "npm run build && npm run build:browserTests && karma start ./karma.config.js --single-run",
"test:browser": "npm run build && npm run build:browserTests && karma start ./karma.config.js",
"test:watch": "jest --watch --verbose false --silent=false --runInBand ./test/**/*.test.ts --testPathIgnorePatterns=./test/integration --testPathIgnorePatterns=./test/fixtures",
"format": "prettier --write '{src,test}/**/*.ts'",
"lint": "eslint . --ext .ts --max-warnings 0",

View File

@@ -1,64 +1,14 @@
'use strict'
const assert = require('assert')
const path = require('path')
const webpack = require('webpack')
const { merge } = require('webpack-merge')
const { webpackForTest } = require('../../../weback.test.config')
function webpackForTest(testFileName) {
const match = testFileName.match(/\/?([^\/]*)\.ts$/)
if (!match) {
assert(false, 'wrong filename:' + testFileName)
}
return merge(require('../webpack.base.config'), {
mode: 'production',
cache: true,
module.exports = merge(
require('../webpack.base.config'),
webpackForTest('./test/integration/index.ts', __dirname),
{
externals: [
{
net: 'null', // net is used in tests to setup mock server
},
],
entry: testFileName,
output: {
library: match[1].replace(/-/g, '_'),
path: path.join(__dirname, './testCompiledForWeb/'),
filename: match[1] + '.js',
},
plugins: [
new webpack.DefinePlugin({
'process.stdout': {},
}),
],
module: {
rules: [
// Compile the tests
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
lib: ['esnext', 'dom'],
composite: false,
declaration: false,
declarationMap: false,
},
},
},
],
},
],
},
node: {
global: true,
__filename: false,
__dirname: true,
},
resolve: {
extensions: ['.ts', '.js', '.json'],
},
})
}
module.exports = [(env, argv) => webpackForTest('./test/integration/index.ts')]
},
)