diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 4cc9daca63e..d054a29f93a 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -81,6 +81,41 @@ jobs: run: npm run test:browser - name: Report Coverage run: npm run codecov:browser + webworker-tests-stable: + runs-on: ubuntu-latest + container: + image: circleci/node:14-browsers + env: + NPM_CONFIG_UNSAFE_PERM: true + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Permission Setup + run: sudo chmod -R 777 /github /__w + + - name: restore lerna + uses: actions/cache@v2 + id: cache + with: + path: | + node_modules + */*/node_modules + key: browser-tests-stable-${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('**/package.json') }} + + - name: Bootstrap + if: steps.cache.outputs.cache-hit != 'true' + run: | + npm install --ignore-scripts + npx lerna bootstrap --no-ci --hoist --nohoist='zone.js' + + - name: Build 🔧 + run: | + npm run compile + + - name: Unit tests + run: npm run test:webworker + - name: Report Coverage + run: npm run codecov:webworker node-tests-experimental: strategy: fail-fast: false @@ -164,3 +199,42 @@ jobs: - name: Report Coverage working-directory: experimental run: npm run codecov:browser + webworker-tests-experimental: + runs-on: ubuntu-latest + container: + image: circleci/node:14-browsers + env: + NPM_CONFIG_UNSAFE_PERM: true + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Permission Setup + run: sudo chmod -R 777 /github /__w + + - name: restore lerna + uses: actions/cache@v2 + id: cache + with: + path: | + experimental/node_modules + experimental/*/*/node_modules + key: browser-tests-experimental-${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('**/package.json') }} + + - name: Bootstrap + if: steps.cache.outputs.cache-hit != 'true' + working-directory: experimental + run: | + npm install --ignore-scripts + npx lerna bootstrap --no-ci --hoist --nohoist='zone.js' + + - name: Build 🔧 + working-directory: experimental + run: | + npm run compile + + - name: Unit tests + working-directory: experimental + run: npm run test:webworker + - name: Report Coverage + working-directory: experimental + run: npm run codecov:webworker diff --git a/karma.base.js b/karma.base.js index cbae813f7ba..7df76d7b132 100644 --- a/karma.base.js +++ b/karma.base.js @@ -26,6 +26,8 @@ module.exports = { }, reporters: ['spec', 'coverage-istanbul'], files: ['test/index-webpack.ts'], - preprocessors: { 'test/index-webpack.ts': ['webpack'] }, + preprocessors: { + 'test/index-webpack*.ts': ['webpack'] + }, webpackMiddleware: { noInfo: true } }; diff --git a/karma.worker.js b/karma.worker.js new file mode 100644 index 00000000000..9a6f9d5eb37 --- /dev/null +++ b/karma.worker.js @@ -0,0 +1,27 @@ +/*! + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const baseConfig = require('./karma.base'); + +module.exports = { + ...baseConfig, + frameworks: ['mocha-webworker'], + + files: [{ + pattern: 'test/index-webpack.worker.ts', + included: false, + }], +}; diff --git a/package.json b/package.json index 693ccde5d66..6798a9a9964 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,13 @@ "version:update": "lerna run version:update", "test": "lerna run test", "test:browser": "lerna run test:browser", + "test:webworker": "lerna run test:webworker", "test:backcompat": "lerna run test:backcompat", "bootstrap": "lerna bootstrap --hoist --nohoist='zone.js'", "changelog": "lerna-changelog", "codecov": "lerna run codecov", "codecov:browser": "lerna run codecov:browser", + "codecov:webworker": "lerna run codecov:webworker", "predocs-test": "npm run docs", "docs": "typedoc && touch docs/.nojekyll", "docs-deploy": "gh-pages --dotfiles --dist docs", diff --git a/packages/opentelemetry-sdk-trace-web/karma.worker.js b/packages/opentelemetry-sdk-trace-web/karma.worker.js new file mode 100644 index 00000000000..d392e58ba60 --- /dev/null +++ b/packages/opentelemetry-sdk-trace-web/karma.worker.js @@ -0,0 +1,24 @@ +/*! + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const karmaWebpackConfig = require('../../karma.webpack'); +const karmaBaseConfig = require('../../karma.worker'); + +module.exports = (config) => { + config.set(Object.assign({}, karmaBaseConfig, { + webpack: karmaWebpackConfig + })) +}; diff --git a/packages/opentelemetry-sdk-trace-web/package.json b/packages/opentelemetry-sdk-trace-web/package.json index 2e88f6520e0..7e6ce6b66f8 100644 --- a/packages/opentelemetry-sdk-trace-web/package.json +++ b/packages/opentelemetry-sdk-trace-web/package.json @@ -13,9 +13,11 @@ "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", + "codecov:webworker": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "version": "node ../../scripts/version-update.js", "tdd": "karma start", "test:browser": "nyc karma start --single-run", + "test:webworker": "nyc karma start karma.worker.js --single-run", "watch": "tsc --build --watch tsconfig.all.json", "precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies", "prewatch": "npm run precompile" @@ -69,6 +71,7 @@ "karma-coverage-istanbul-reporter": "3.0.3", "karma-jquery": "0.2.4", "karma-mocha": "2.0.1", + "karma-mocha-webworker": "1.3.0", "karma-spec-reporter": "0.0.32", "karma-webpack": "4.0.2", "mocha": "7.2.0", diff --git a/packages/opentelemetry-sdk-trace-web/test/StackContextManager.test.ts b/packages/opentelemetry-sdk-trace-web/test/StackContextManager.test.ts index 1509780e7ba..8fb1e34d130 100644 --- a/packages/opentelemetry-sdk-trace-web/test/StackContextManager.test.ts +++ b/packages/opentelemetry-sdk-trace-web/test/StackContextManager.test.ts @@ -111,7 +111,7 @@ describe('StackContextManager', () => { assert.strictEqual(contextManager.active(), ctx1); return done(); }); - assert.strictEqual(contextManager.active(), window); + assert.strictEqual(contextManager.active(), globalThis); }); it('should finally restore an old context when context is an object', done => { @@ -130,7 +130,7 @@ describe('StackContextManager', () => { assert.strictEqual(contextManager.active(), ctx1); return done(); }); - assert.strictEqual(contextManager.active(), window); + assert.strictEqual(contextManager.active(), globalThis); }); it('should forward this, arguments and return value', () => { diff --git a/packages/opentelemetry-sdk-trace-web/test/index-webpack.ts b/packages/opentelemetry-sdk-trace-web/test/index-webpack.ts index 061a48ccfa7..e455815ca9a 100644 --- a/packages/opentelemetry-sdk-trace-web/test/index-webpack.ts +++ b/packages/opentelemetry-sdk-trace-web/test/index-webpack.ts @@ -13,8 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const testsContext = require.context('.', true, /test$/); -testsContext.keys().forEach(testsContext); -const srcContext = require.context('.', true, /src$/); -srcContext.keys().forEach(srcContext); +{ + const testsContext = require.context('./', false, /test$/); + testsContext.keys().forEach(testsContext); +} + +{ + const testsContext = require.context('./window', false, /test$/); + testsContext.keys().forEach(testsContext); +} diff --git a/packages/opentelemetry-sdk-trace-web/test/index-webpack.worker.ts b/packages/opentelemetry-sdk-trace-web/test/index-webpack.worker.ts new file mode 100644 index 00000000000..4ee65b7b123 --- /dev/null +++ b/packages/opentelemetry-sdk-trace-web/test/index-webpack.worker.ts @@ -0,0 +1,18 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const testsContext = require.context('./', false, /test$/); +testsContext.keys().forEach(testsContext); diff --git a/packages/opentelemetry-sdk-trace-web/test/utils.test.ts b/packages/opentelemetry-sdk-trace-web/test/utils.test.ts index b8217e4f135..f870450013d 100644 --- a/packages/opentelemetry-sdk-trace-web/test/utils.test.ts +++ b/packages/opentelemetry-sdk-trace-web/test/utils.test.ts @@ -27,7 +27,6 @@ import * as sinon from 'sinon'; import { addSpanNetworkEvent, addSpanNetworkEvents, - getElementXPath, getResource, normalizeUrl, parseUrl, @@ -48,45 +47,6 @@ function createHrTime(startTime: HrTime, addToStart: number): HrTime { } return [seconds, nanos]; } -const fixture = ` -