Skip to content

Commit

Permalink
feat: Faster grpc-web tests (#1608)
Browse files Browse the repository at this point in the history
  • Loading branch information
fundthmcalculus authored Mar 11, 2024
1 parent 01e74b2 commit ebdc0e6
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/test-infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
name: "Install packages"
shell: pwsh
working-directory: ./sdk/web
- run: npm run test:browser -- --trinsic_environment="${{ inputs.environment }}"
- run: npm run test:grpc-web-tests -- --trinsic_environment="${{ inputs.environment }}"
name: "Run grpc-web tests"
shell: pwsh
working-directory: ./sdk/web
116 changes: 116 additions & 0 deletions web/.config/karma.grpc-web.conf.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// const webpackConfig = require("./webpack.config.js");
const { resolve } = require("path");
const { SourceMapDevToolPlugin, ProvidePlugin } = require("webpack");
const path = require("path");
module.exports = async (config) => {
config.set({
plugins: [
"karma-webpack",
"karma-jasmine",
"karma-coverage",
"karma-chrome-launcher",
"karma-jasmine-html-reporter",
],

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: "..",

singleRun: true, // run and exit for CI pipelines, lol

client: {
clearContext: true, // will show the results in node once all the testcases are loaded
args: config.trinsic_environment ? ["--trinsic_environment="+config.trinsic_environment] : [],
},

reporters: ["kjhtml", "progress", "coverage"],
coverageReporter: {
reporters: [
{
type: "cobertura",
},
],
},

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ["jasmine", "webpack"],

// list of files / patterns to load in the node
// Here I'm including all the Jest tests which are all under the __tests__ directory.
// You may need to tweak this pattern to find your test files/
files: [
{
pattern: "test/**/ProviderService.test.ts",
watched: false,
included: true,
served: true,
},
{
pattern: "**/*.wasm",
watched: false,
included: false,
served: true,
},
],

// preprocess matching files before serving them to the node
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
// Use webpack to bundle our tests files
"test/**/ProviderService.test.ts": ["webpack"],
// Report coverage
"src/**/*.ts": ["coverage"],
},
// "Chrome", "ChromeHeadless"
browsers: ["ChromeHeadless"],

webpackMiddleware: {
stats: "errors-only",
bail: true,
},

port: 9876,

colors: true,

// autoWatch: false,
logLevel: config.LOG_INFO,

webpack: {
mode: "development",
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: "ts-loader",
options: {
configFile: "tsconfig.json",
},
},
],
},
resolve: {
extensions: [".ts", ".js"],
},
output: {
path: resolve(__dirname, "../test/build"),
globalObject: "this",
libraryExport: "default",
},
plugins: [
new SourceMapDevToolPlugin({
filename: null,
test: /\.(ts|js)($|\?)/i,
}),
],
experiments: {
asyncWebAssembly: true,
},
stats: {
errorDetails: true,
},
},
});
};
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"build:typescript": "npx tsc",
"test:node": "jest --config .config/jest.config.cjs --no-cache",
"test:browser": "karma start .config/karma.conf.cjs",
"test:grpc-web-tests": "karma start .config/karma.grpc-web.conf.cjs",
"test": "npm run test:node && npm run test:browser",
"build-and-test": "npm run build && npx run test"
},
Expand Down

0 comments on commit ebdc0e6

Please sign in to comment.