Skip to content

Commit

Permalink
test(sdk-trace-web): run sdk tests on web worker
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Jan 17, 2022
1 parent 57e3299 commit 9e66f92
Show file tree
Hide file tree
Showing 11 changed files with 354 additions and 153 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:browser
node-tests-experimental:
strategy:
fail-fast: false
Expand Down Expand Up @@ -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:browser
4 changes: 3 additions & 1 deletion karma.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};
27 changes: 27 additions & 0 deletions karma.worker.js
Original file line number Diff line number Diff line change
@@ -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,
}],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"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",
Expand Down
24 changes: 24 additions & 0 deletions packages/opentelemetry-sdk-trace-web/karma.worker.js
Original file line number Diff line number Diff line change
@@ -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
}))
};
2 changes: 2 additions & 0 deletions packages/opentelemetry-sdk-trace-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"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"
Expand Down Expand Up @@ -69,6 +70,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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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', () => {
Expand Down
13 changes: 9 additions & 4 deletions packages/opentelemetry-sdk-trace-web/test/index-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
18 changes: 18 additions & 0 deletions packages/opentelemetry-sdk-trace-web/test/index-webpack.worker.ts
Original file line number Diff line number Diff line change
@@ -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);
Loading

0 comments on commit 9e66f92

Please sign in to comment.