Skip to content

Commit 02d44d9

Browse files
author
Beatriz Rizental
authored
Merge pull request #342 from brizental/1682282-schema-validation
Bug 1682282 - Add tests to validate generated pings against the schema
2 parents a014595 + a17d2e0 commit 02d44d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+950
-193
lines changed

.circleci/config.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ jobs:
3535
name: Run circular dependencies checker
3636
command: npm --prefix ./glean run lint:circular-deps
3737

38-
unit-tests:
38+
test:
3939
docker:
40-
- image: cimg/node:16.1.0
40+
- image: cimg/python:3.9.4-node
4141
steps:
4242
- checkout
4343
- run:
@@ -51,7 +51,10 @@ jobs:
5151
command: npm --prefix ./glean install
5252
- run:
5353
name: Run unit tests
54-
command: export PATH=.:$PATH && npm --prefix ./glean run test
54+
command: export PATH=.:$PATH && npm --prefix ./glean run test:unit
55+
- run:
56+
name: Run integration tests
57+
command: export PATH=.:$PATH && npm --prefix ./glean run test:integration
5558

5659
samples-tests:
5760
docker:
@@ -196,7 +199,7 @@ workflows:
196199
ci:
197200
jobs:
198201
- lint
199-
- unit-tests
202+
- test
200203
- check-qt-js
201204
- samples-tests
202205
- docs-deploy:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.14.0...main)
44

5+
* [#342](https://github.com/mozilla/glean.js/pull/342): BUGFIX: Fix timespan payload representatin to match exactly the payload expected according to the Glean schema.
6+
57
# v0.14.0 (2021-05-19)
68

79
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.13.0...v0.14.0)

bin/parser-for-schema-testing.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
set -eo pipefail
8+
9+
run() {
10+
[ "${VERB:-0}" != 0 ] && echo "+ $*"
11+
"$@"
12+
}
13+
14+
# All sed commands below work with either
15+
# GNU sed (standard on Linux distrubtions) or BSD sed (standard on macOS)
16+
SED="sed"
17+
18+
WORKSPACE_ROOT="$( cd "$(dirname "$0")/.." ; pwd -P )"
19+
20+
# Generate files using the Glean.js CLI tool (which just runs glean_parser)
21+
npm run cli -- \
22+
translate tests/integration/schema/metrics.yaml tests/integration/schema/pings.yaml \
23+
-f typescript \
24+
-o tests/integration/schema/generated
25+
26+
# Update metrics import path
27+
FILE=glean/tests/integration/schema/generated/forTesting.ts
28+
run $SED -i.bak -E \
29+
-e 's#@mozilla/glean/webext/private/metrics#../../../../src/core/metrics/types#g' \
30+
"${WORKSPACE_ROOT}/${FILE}"
31+
run rm "${WORKSPACE_ROOT}/${FILE}.bak"
32+
33+
# Update ping import path
34+
FILE=glean/tests/integration/schema/generated/pings.ts
35+
run $SED -i.bak -E \
36+
-e 's#@mozilla/glean/webext/private/ping#../../../../src/core/pings/ping_type.js#g' \
37+
"${WORKSPACE_ROOT}/${FILE}"
38+
run rm "${WORKSPACE_ROOT}/${FILE}.bak"
39+

docs/adding_a_new_metric_type.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async function testGetValue(ping: string = this.sendInPings[0]): Promise<string
171171
172172
## Testing
173173

174-
Tests for metric type implementations live under the `glean/tests/core/metrics/types` folder. Create a new
174+
Tests for metric type implementations live under the `glean/tests/unit/core/metrics/types` folder. Create a new
175175
file with the same name as the one you created in `glean/src/core/metrics/types` to accomodate your
176176
metric type tests.
177177

@@ -181,6 +181,17 @@ Make sure your tests cover at least your metric types basic functionality:
181181
- The metric correctly reports errors;
182182
- The metric returns the correct value when it has value.
183183

184+
### Glean schema
185+
186+
It is very important to also check if the new metric payload is valid against the Glean schema.
187+
Declare a new instance of the metrics you just implemented in `glean/test/integration/schema/metrics.yaml`
188+
and then make sure you record to that metrics on the `validate generated ping is valid against glean schema`
189+
test on the `glean/test/integration/schema/schema.spec.ts` test.
190+
191+
This test will fail unless schema changes to accomodate the new metric type have already landed.
192+
Please see the [mozilla-pipeline-schemas](#mozilla-pipeline-schemas) section on how to add new metric
193+
types to the Glean schema.
194+
184195
## Documentation
185196

186197
Glean.js' has linter rules that enforce [JSDoc](https://jsdoc.app/) strings on every public function.

docs/getting_started.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,29 @@ npm run test
2828
```
2929
in the `glean` folder.
3030

31-
This runs all the tests in the `glean` folder.
31+
This runs all the tests in the `glean` folder.
3232
Alternatively, you may want to run component-specific tests.
3333
To do so, substitute `test` in the command above with one of the followings:
34-
* `test:core` - executes tests inside `tests/core` folder.
35-
* `test:plugins` - executes tests inside `tests/plugins` folder.
36-
* `test:platform` - executes tests inside `tests/platform` folder.
34+
35+
* `test:unit:core` - executes tests inside `tests/unit/core` folder.
36+
* `test:unit:plugins` - executes tests inside `tests/unit/plugins` folder.
37+
* `test:unit:platform` - executes tests inside `tests/unit/platform` folder.
38+
* `test:integration` - executes tests inside `tests/integration` folder.
3739

3840
You might want to run one specific test within a certain folder.
3941
To run the test with the title `DatetimeMetric` in the `core` folder:
4042
```bash
41-
npm run test:core -- --grep "DateTimeMetric"
43+
npm run test:unit:core -- --grep "DateTimeMetric"
4244
```
4345
You should see the output similar to the following:
4446
```shell
4547

46-
> @mozilla/[email protected] test:core
47-
> npm run test:base -- "tests/core/**/*.spec.ts" --recursive "--grep" "DatetimeMetric"
48+
> @mozilla/[email protected] test:unit:core
49+
> npm run test:base -- "tests/unit/core/**/*.spec.ts" --recursive "--grep" "DatetimeMetric"
4850

4951

5052
> @mozilla/[email protected] test:base
51-
> node --experimental-modules --experimental-specifier-resolution=node --loader=ts-node/esm node_modules/mocha/lib/cli/cli.js "tests/core/**/*.spec.ts" "--recursive" "--grep" "DatetimeMetric"
53+
> node --experimental-modules --experimental-specifier-resolution=node --loader=ts-node/esm node_modules/mocha/lib/cli/cli.js "tests/unit/core/**/*.spec.ts" "--recursive" "--grep" "DatetimeMetric"
5254

5355
(node:52217) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
5456
(Use `node --trace-warnings ...` to show where the warning was created)

0 commit comments

Comments
 (0)