Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update karma-webpack to v5.0.1, adapt tests #4648

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed so that we mock the right thing for the right platform, process is now defined due to the required polyfill, so we're using process?.versions?.node instead to determine if we're running in Node.js or the browser.

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