Skip to content

Commit

Permalink
chore: update karma-webpack to v5.0.1, adapt tests (#4648)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency karma-webpack to v5

* feat: add polyfills missing from webpack 5, adapt tests, split up raw env parsing into browser/node specific code

---------

Co-authored-by: Mend Renovate <[email protected]>
  • Loading branch information
pichlermarc and renovate-bot authored May 2, 2024
1 parent 157c811 commit 9400e72
Show file tree
Hide file tree
Showing 39 changed files with 21,795 additions and 26,658 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

* fix(sdk-trace-web): fix invalid timings in span events [#4486](https://github.com/open-telemetry/opentelemetry-js/pull/4486) @Abinet18
* fix(resources): ensure BrowserDetector does not think Node.js v21 is a browser [#4561](https://github.com/open-telemetry/opentelemetry-js/issues/4561) @trentm
* fix(core): align inconsistent behavior of `getEnv()` and `getEnvWithoutDefaults()` when a `process` polyfill is used [#4648](https://github.com/open-telemetry/opentelemetry-js/pull/4648) @pichlermarc
* `getEnvWithoutDefaults()` would use `process.env` if it was defined when running in a browser, while `getEnv()` would always use `_globalThis`. Now both use `_globalThis` when running in a browser.

## 1.23.0

Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"karma-mocha": "2.0.1",
"karma-mocha-webworker": "1.3.0",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"memfs": "3.5.3",
"mocha": "10.2.0",
Expand Down
11 changes: 8 additions & 3 deletions api/test/common/internal/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
import * as assert from 'assert';
import { VERSION } from '../../../src/version';

describe('version', () => {
it('should have generated VERSION.ts', () => {
describe('version', function () {
it('should have generated VERSION.ts', function () {
// Skip in case we're not running in Node.js
if (global.process?.versions?.node === undefined) {
this.skip();
}

const pjson = require('../../../package.json');
assert.strictEqual(pjson.version, VERSION);
});

it('prerelease tag versions are banned', () => {
it('prerelease tag versions are banned', function () {
// see https://github.com/open-telemetry/opentelemetry-js-api/issues/74
assert.ok(VERSION.match(/^\d+\.\d+\.\d+$/));
});
Expand Down
2 changes: 1 addition & 1 deletion experimental/packages/api-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
2 changes: 1 addition & 1 deletion experimental/packages/api-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
2 changes: 1 addition & 1 deletion experimental/packages/exporter-logs-otlp-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('OTLPLogExporter', () => {
sinon.restore();
});

if (typeof process === 'undefined') {
if (global.process?.versions?.node === undefined) {
envSource = globalThis as unknown as Record<string, any>;
} else {
envSource = process.env as Record<string, any>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getDefaultUrl } from '../src/platform/config';
describe('getDefaultUrl', () => {
let envSource: Record<string, any>;

if (typeof process === 'undefined') {
if (global.process?.versions?.node === undefined) {
envSource = globalThis as unknown as Record<string, any>;
} else {
envSource = process.env as Record<string, any>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('OTLPLogExporter', () => {
sinon.restore();
});

if (typeof process === 'undefined') {
if (global.process?.versions?.node === undefined) {
envSource = globalThis as unknown as Record<string, any>;
} else {
envSource = process.env as Record<string, any>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
2 changes: 1 addition & 1 deletion experimental/packages/otlp-exporter-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
2 changes: 1 addition & 1 deletion experimental/packages/otlp-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
2 changes: 1 addition & 1 deletion experimental/packages/sdk-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"karma-coverage": "2.2.1",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "4.0.2",
"karma-webpack": "5.0.1",
"lerna": "6.6.2",
"mocha": "10.2.0",
"nyc": "15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Logger } from '../../src/Logger';
describe('LoggerProvider', () => {
let envSource: Record<string, any>;

if (typeof process === 'undefined') {
if (global.process?.versions?.node === undefined) {
envSource = globalThis as unknown as Record<string, any>;
} else {
envSource = process.env as Record<string, any>;
Expand Down
27 changes: 20 additions & 7 deletions karma.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,34 @@
* limitations under the License.
*/

const webpackNodePolyfills = require('./webpack.node-polyfills.js');
const webpack = require('webpack')

// This is the webpack configuration for browser Karma tests with coverage.
module.exports = {
mode: 'development',
target: 'web',
output: { filename: 'bundle.js' },
resolve: { extensions: ['.ts', '.js'] },
output: {filename: 'bundle.js'},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
// Enable the assert library polyfill because that is used in tests
"assert": require.resolve('assert/'),
"util": require.resolve('util/'),
},
},
devtool: 'eval-source-map',
plugins: [
new webpack.ProvidePlugin({
// Make a global `process` variable that points to the `process` package,
// because the `util` package expects there to be a global variable named `process`.
// Thanks to https://stackoverflow.com/a/65018686/14239942
// NOTE: I wish there was a better way as this pollutes the tests with a defined 'process' global.
process: 'process/browser'
})
],
module: {
rules: [
{ test: /\.ts$/, use: 'ts-loader' },
{test: /\.ts$/, use: 'ts-loader'},
{
test: /\.js$/,
exclude: {
Expand Down Expand Up @@ -53,9 +69,6 @@ module.exports = {
}
},
},
// This setting configures Node polyfills for the browser that will be
// added to the webpack bundle for Karma tests.
{ parser: { node: webpackNodePolyfills } },
],
},
};
Loading

0 comments on commit 9400e72

Please sign in to comment.