mozilla-rally / rally

A monorepo for Rally project containing Rally SDK, Rally Web Platform and Extensions.
Mozilla Public License 2.0
7 stars 6 forks source link

set up unit test for extension #428

Open rhelmer opened 1 year ago

rhelmer commented 1 year ago

Trying to get unit tests working for attention stream extension, Glean.js isn't being bundled correctly by rollup.

I recall that we hit an issue with the cloud functions where we had to switch to ES modules, because Glean doesn't export CommonJS modules in the way the bundler wanted.

Details:

    /Users/roberthelmer/src/rally/extensions/attention-stream/node_modules/@mozilla/glean/dist/plugins/encryption.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { CompactEncrypt, importJWK, calculateJwkThumbprint } from "jose";
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      13 | import { Rally, RunStates } from "@mozilla/rally-sdk";
      14 |
    > 15 | import PingEncryptionPlugin from "@mozilla/glean/plugins/encryption";
         | ^
      16 | import Glean, {
      17 |   Uploader,
      18 |   UploadResult,

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)
      at Object.<anonymous> (src/background.ts:15:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.687s
rhelmer commented 1 year ago

Jest has experimental (due to it being experimental in Node) support for modules: https://jestjs.io/docs/ecmascript-modules

IIRC this is what we do for our cloud functions, we could consider doing the same here, if only for tests.