diff --git a/.github/workflows/test-infrastructure.yml b/.github/workflows/test-infrastructure.yml index 6d9e8ef75..774232fe7 100644 --- a/.github/workflows/test-infrastructure.yml +++ b/.github/workflows/test-infrastructure.yml @@ -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 diff --git a/web/.config/karma.grpc-web.conf.cjs b/web/.config/karma.grpc-web.conf.cjs new file mode 100644 index 000000000..4bcba53d4 --- /dev/null +++ b/web/.config/karma.grpc-web.conf.cjs @@ -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, + }, + }, + }); +}; diff --git a/web/package.json b/web/package.json index 877dda436..bc65f6d15 100644 --- a/web/package.json +++ b/web/package.json @@ -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" },