From ec240db577006a275ab4d7515f4d50dff1f99837 Mon Sep 17 00:00:00 2001 From: surilindur <16085353+surilindur@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:31:19 +0100 Subject: [PATCH] Update Karma configurations --- karma.conf.ts | 71 +++++++++++++++++++++ karma.config.js | 104 ------------------------------- karma-setup.js => karma.setup.ts | 4 +- package.json | 1 + tsconfig.eslint.json | 4 +- yarn.lock | 26 ++++++++ 6 files changed, 103 insertions(+), 107 deletions(-) create mode 100644 karma.conf.ts delete mode 100644 karma.config.js rename karma-setup.js => karma.setup.ts (83%) diff --git a/karma.conf.ts b/karma.conf.ts new file mode 100644 index 000000000..d40f3f629 --- /dev/null +++ b/karma.conf.ts @@ -0,0 +1,71 @@ +import { webkit } from '@playwright/test'; +import * as NodePolyfillPlugin from 'node-polyfill-webpack-plugin'; +import { DefinePlugin } from 'webpack'; + +const testFiles = [ + 'engines/query-sparql-link-traversal-solid/test/QuerySparqlLinkTraversalSolid-solidbench-test.ts', +]; + +process.env.WEBKIT_HEADLESS_BIN = webkit.executablePath(); + +// Based on https://github.com/tom-sherman/blog/blob/main/posts/02-running-jest-tests-in-a-browser.md +function defineConfig(config: any): void { + config.set({ + basePath: __dirname, + plugins: [ + 'karma-webpack', + 'karma-jasmine', + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-webkit-launcher', + 'karma-sourcemap-loader', + 'karma-jasmine-html-reporter', + ], + frameworks: [ 'jasmine', 'webpack' ], + files: [ './karma.setup.ts', ...testFiles ], + client: { + args: [ '--grep', '/^(?!.*no browser).*$/' ], + }, + preprocessors: { + './karma.setup.ts': [ 'webpack' ], + ...Object.fromEntries(testFiles.map(testFile => [ testFile, [ 'webpack', 'sourcemap' ]])), + }, + webpack: { + devtool: 'inline-source-map', + mode: 'production', + module: { + rules: [ + { + test: /\.ts$/u, + loader: 'ts-loader', + exclude: /node_modules/u, + options: { transpileOnly: true }, + }, + ], + }, + plugins: [ + new NodePolyfillPlugin({ + additionalAliases: [ + 'process', + ], + }), + new DefinePlugin({ 'process.stdout.isTTY': false }), + ], + resolve: { + alias: { + fs: false, + module: false, + 'jest.unmock': false, + }, + extensions: [ '.js', '.ts' ], + }, + }, + browsers: [ + 'ChromeHeadless', + 'FirefoxHeadless', + 'WebkitHeadless', + ], + }); +}; + +export default defineConfig; diff --git a/karma.config.js b/karma.config.js deleted file mode 100644 index e8d989e4e..000000000 --- a/karma.config.js +++ /dev/null @@ -1,104 +0,0 @@ -const Path = require('node:path'); -const NodePolyfillPlugin = require('node-polyfill-webpack-plugin'); -const webpack = require('webpack'); - -const testFiles = [ - 'engines/query-sparql-link-traversal-solid/test/QuerySparqlLinkTraversalSolid-solidbench-test.ts', -]; - -// Based on https://github.com/tom-sherman/blog/blob/main/posts/02-running-jest-tests-in-a-browser.md -module.exports = function(config) { - config.set({ - basePath: '', - browserNoActivityTimeout: 100_000, - plugins: [ - 'karma-webpack', - 'karma-jasmine', - 'karma-chrome-launcher', - 'karma-firefox-launcher', - 'karma-sourcemap-loader', - 'karma-jasmine-html-reporter', - ], - frameworks: [ 'jasmine', 'webpack' ], - - files: [ './karma-setup.js', ...testFiles ], - client: { - args: [ '--grep', '/^(?!.*no browser).*$/' ], - jasmine: { - timeoutInterval: 50_000, - }, - }, - preprocessors: { - './karma-setup.js': [ 'webpack' ], - ...Object.fromEntries(testFiles.map(key => [ key, [ 'webpack', 'sourcemap' ]])), - }, - - webpack: { - mode: 'production', - devtool: 'inline-source-map', - resolve: { - alias: { - fs: false, - module: false, - [Path.resolve(__dirname, 'engines/query-sparql-link-traversal-solid/test/util.js')]: Path.resolve(__dirname, 'engines/query-sparql-link-traversal-solid/test/util-browser.js'), - 'jest.unmock': false, - }, - extensions: [ '.js', '.jsx', '.ts', '.tsx' ], - }, - module: { - rules: [ - { - test: /\.tsx?$/u, - loader: 'ts-loader', - exclude: /node_modules/u, - options: { transpileOnly: true }, - }, - { - test: /\.sparql$/u, - use: 'raw-loader', - }, - ], - }, - plugins: [ - new NodePolyfillPlugin({ - additionalAliases: [ 'process' ], - }), - new webpack.DefinePlugin({ - 'process.stdout.isTTY': false, - }), - ], - ignoreWarnings: [ - { - module: /jest/u, - }, - { - module: /karma-setup/u, - }, - ], - stats: { - colors: true, - hash: false, - version: false, - timings: false, - assets: false, - chunks: false, - modules: false, - reasons: false, - children: false, - source: false, - errors: false, - errorDetails: false, - warnings: false, - publicPath: false, - }, - performance: { - hints: false, - }, - }, - - browsers: [ - 'ChromeHeadless', - 'FirefoxHeadless', - ], - }); -}; diff --git a/karma-setup.js b/karma.setup.ts similarity index 83% rename from karma-setup.js rename to karma.setup.ts index 8c7dd191f..ff3b92cda 100644 --- a/karma-setup.js +++ b/karma.setup.ts @@ -9,5 +9,5 @@ window.test.each = inputs => (testName, test) => { } }; window.test.todo = function() {}; -window.jest = jest; -window.expect = expect; +(window).jest = jest; +(window).expect = expect; diff --git a/package.json b/package.json index 1e0e45a47..23d155f17 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "@comunica/packager": "4.0.1", "@comunica/utils-jest": "4.0.2", "@comunica/utils-monorepo": "4.0.1", + "@playwright/test": "^1.49.0", "@pollyjs/adapter-node-http": "^6.0.6", "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 285252e99..ff3d498bf 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -2,7 +2,9 @@ "extends": "./tsconfig.json", "include": [ "engines/**/*.ts", - "packages/**/*.ts" + "packages/**/*.ts", + "karma.conf.ts", + "karma.setup.ts" ], "exclude": [ "**/node_modules" diff --git a/yarn.lock b/yarn.lock index 80807a1a3..e4c32b868 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8742,6 +8742,13 @@ resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.1.1.tgz#1ec17e2edbec25c8306d424ecfbf13c7de1aaa31" integrity sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA== +"@playwright/test@^1.49.0": + version "1.49.0" + resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.49.0.tgz#74227385b58317ee076b86b56d0e1e1b25cff01e" + integrity sha512-DMulbwQURa8rNIQrf94+jPJQ4FmOVdpE5ZppRNvWVjvhC+6sOeo28r8MgIpQRYouXRtt/FCCXU7zn20jnHR4Qw== + dependencies: + playwright "1.49.0" + "@pollyjs/adapter-node-http@^6.0.6": version "6.0.6" resolved "https://registry.yarnpkg.com/@pollyjs/adapter-node-http/-/adapter-node-http-6.0.6.tgz#7122765604e3dfdd6d68bced8a89c7966d49d710" @@ -13217,6 +13224,11 @@ fs.realpath@^1.0.0: resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== +fsevents@2.3.2: + version "2.3.2" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + fsevents@^2.3.2, fsevents@~2.3.2: version "2.3.3" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" @@ -17312,6 +17324,20 @@ pkg-types@^1.0.3, pkg-types@^1.1.1: mlly "^1.7.0" pathe "^1.1.2" +playwright-core@1.49.0: + version "1.49.0" + resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.49.0.tgz#8e69ffed3f41855b854982f3632f2922c890afcb" + integrity sha512-R+3KKTQF3npy5GTiKH/T+kdhoJfJojjHESR1YEWhYuEKRVfVaxH3+4+GvXE5xyCngCxhxnykk0Vlah9v8fs3jA== + +playwright@1.49.0: + version "1.49.0" + resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.49.0.tgz#df6b9e05423377a99658202844a294a8afb95d0a" + integrity sha512-eKpmys0UFDnfNb3vfsf8Vx2LEOtflgRebl0Im2eQQnYMA4Aqd+Zw8bEOB+7ZKvN76901mRnqdsiOGKxzVTbi7A== + dependencies: + playwright-core "1.49.0" + optionalDependencies: + fsevents "2.3.2" + please-upgrade-node@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz#aeddd3f994c933e4ad98b99d9a556efa0e2fe942"