Skip to content
3 changes: 2 additions & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"spec": "test/**/*.test.ts",
"exclude": [
"test/dist/*.{js,ts}",
"test/feature/*.{js,ts}"
"test/feature/*.{js,ts}",
"test/integration/shared-worker/*.{js,ts}"
],
"timeout": 5000,
"reporter": "spec"
Expand Down
134 changes: 134 additions & 0 deletions karma/shared-worker.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
const process = require('process');

module.exports = function (config) {
config.set({
// Base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '../',

// Frameworks to use
frameworks: ['mocha', 'chai'],

// List of files / patterns to load in the browser
files: [
// Include the built PubNub library
'dist/web/pubnub.js',
// Include the shared worker file
{ pattern: 'dist/web/pubnub.worker.js', included: false, served: true },
// Include the test file
'test/integration/shared-worker/shared-worker.test.ts',
],

// List of files to exclude
exclude: [],

// Preprocess matching files before serving them to the browser
preprocessors: {
'test/**/*.ts': ['webpack', 'sourcemap'],
},

// Webpack configuration
webpack: {
mode: 'development',
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
"crypto": false,
"stream": false,
"buffer": require.resolve("buffer"),
"util": require.resolve("util/"),
"url": false,
"querystring": false,
"path": false,
"fs": false,
"net": false,
"tls": false,
"os": false,
"process": require.resolve("process/browser"),
},
},
plugins: [
new (require('webpack')).ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
],
devtool: 'inline-source-map',
stats: 'errors-only',
},

webpackMiddleware: {
logLevel: 'error',
},

// Test results reporter to use
reporters: ['spec'],

// Web server port
port: 9876,

// Enable / disable colors in the output (reporters and logs)
colors: true,

// Level of logging
logLevel: config.LOG_INFO,

// Enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

// Start these browsers
browsers: ['Chrome_SharedWorker'],

// Continuous Integration mode
singleRun: true,

// Browser disconnect timeout
browserDisconnectTimeout: 30000,

// Browser no activity timeout
browserNoActivityTimeout: 30000,

// Capture timeout
captureTimeout: 30000,

// Custom launcher for shared worker testing
customLaunchers: {
Chrome_SharedWorker: {
base: 'ChromeHeadless',
flags: [
'--disable-web-security',
'--disable-features=VizDisplayCompositor',
'--enable-shared-worker',
'--allow-running-insecure-content',
'--disable-background-timer-throttling',
'--disable-renderer-backgrounding',
'--disable-backgrounding-occluded-windows',
'--no-sandbox',
'--disable-setuid-sandbox',
],
},
},

// Client configuration
client: {
mocha: {
timeout: 30000, // Longer timeout for network tests
reporter: 'spec',
},
captureConsole: true,
},

// Proxies for serving worker files
proxies: {
'/dist/': '/base/dist/',
},
});
};
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"build:node-types": "ts-node ./.scripts/types-aggregate.ts --ts-config=./tsconfig.json --package=PubNub --working-dir=./lib/types --input=./lib/types/node/index.d.ts --output=./lib/types",
"test": "npm run test:web && npm run test:node",
"test:web": "karma start karma/web.config.cjs",
"test:web:shared-worker": "karma start karma/shared-worker.config.js",
"test:node": "TS_NODE_PROJECT='./tsconfig.json' mocha --project tsconfig.mocha.json",
"clean": "rimraf lib dist upload",
"lint": "eslint \"src/**/*\" --config .eslintrc.cjs",
"test:snippets": "tsc --project docs-snippets/tsconfig.json --noEmit",
"ci": "npm run clean && npm run build && npm run lint && npm run test",
"ci:web": "npm run clean && npm run build:web && npm run lint && npm run test:web",
"ci:web": "npm run clean && npm run build:web && npm run lint && npm run test:web && npm run test:web:shared-worker",
"ci:node": "npm run clean && npm run build:node && npm run lint && npm run test:node",
"test:feature:objectsv2:node": "NODE_ENV=test TS_NODE_PROJECT='./tsconfig.json' mocha --project tsconfig.mocha.json --require tsx --no-config --reporter spec test/dist/objectsv2.test.ts",
"test:feature:fileupload:node": "NODE_ENV=test TS_NODE_PROJECT='./tsconfig.json' mocha --project tsconfig.mocha.json --require tsx --no-config --reporter spec test/feature/file_upload.node.test.ts",
Expand Down Expand Up @@ -103,11 +104,13 @@
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^2.0.1",
"karma-sinon-chai": "^2.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-sourcemap-loader": "^0.3.8",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "^5.0.1",
"mocha": "10.4.0",
"nock": "^14.0.3",
"prettier": "^3.2.5",
"process": "^0.11.10",
"rimraf": "^3.0.2",
"rollup": "4.22.4",
"rollup-plugin-gzip": "^3.1.2",
Expand All @@ -116,10 +119,13 @@
"sinon-chai": "^3.3.0",
"source-map-support": "^0.5.21",
"ts-mocha": "^10.0.0",
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"tsx": "^4.7.1",
"typescript": "^5.4.5",
"underscore": "^1.9.2",
"util": "^0.12.5",
"webpack": "^5.99.9",
"why-is-node-running": "^3.2.2",
"wtfnode": "^0.10.0"
},
Expand Down
Loading