From 99f17c2a33b6120ba29abd0016c04c614f8a80ce Mon Sep 17 00:00:00 2001 From: Ev Haus Date: Sat, 2 Mar 2024 23:34:02 -0800 Subject: [PATCH] Fix jasmine runs for local testing and tape runs on CI --- README.md | 4 ++-- benchmarks/jasmine/spec/helpers/happydom.ts | 9 ++++++--- benchmarks/tape/helpers/happydom.ts | 12 +++++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 02d9c11..8fbed4e 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,11 @@ hyperfine --warmup 1 \ ## Suites - `jasmine`: This is our baseline, using Jasmine and happy-dom. - - *NOTE*: Jasmine doesn't support shapshot testing so those tests do a basic comparison + - *NOTE*: Jasmine doesn't support shapshot testing so those tests do a basic object comparison - `bun`: Same test suite, but running using Bun. - `jest`: Same test suite, but running using Jest. - `tape`: Same test suite, but running using Tape and ts-node. - - *NOTE*: Tape doesn't support shapshot testing so those tests do a basic comparison + - *NOTE*: Tape doesn't support shapshot testing so those tests do a basic object comparison - `vitest`: Same test suite, but running using Vitest. *NOTE*: That benchmarks use `--poolOptions.threads.isolate=false` as it has the best performance (see [this comment](https://github.com/vitest-dev/vitest/issues/579#issuecomment-1946462435)) ## Results diff --git a/benchmarks/jasmine/spec/helpers/happydom.ts b/benchmarks/jasmine/spec/helpers/happydom.ts index 477f48a..1111357 100644 --- a/benchmarks/jasmine/spec/helpers/happydom.ts +++ b/benchmarks/jasmine/spec/helpers/happydom.ts @@ -7,9 +7,6 @@ global.window = window; // Register global window extensions [ 'document', - // NOTE: This is need for running tests on GitHub Actions CI, but causes - // failure on local builds due to this error: - // > Cannot set property navigator of # which has only a getter 'navigator', 'Element', 'getComputedStyle', @@ -19,5 +16,11 @@ global.window = window; try { global[key] = global.window[key]; } catch (e) { + // NOTE: This is need for running tests on GitHub Actions CI, but causes + // failure on local builds due to this error: + // > Cannot set property navigator of # which has only a getter + if (!e.message.includes('Cannot set property navigator')) { + throw e; + } } }); \ No newline at end of file diff --git a/benchmarks/tape/helpers/happydom.ts b/benchmarks/tape/helpers/happydom.ts index ecfc539..1111357 100644 --- a/benchmarks/tape/helpers/happydom.ts +++ b/benchmarks/tape/helpers/happydom.ts @@ -7,10 +7,20 @@ global.window = window; // Register global window extensions [ 'document', + 'navigator', 'Element', 'getComputedStyle', 'HTMLElement', 'SVGElement' ].forEach((key) => { - global[key] = global.window[key]; + try { + global[key] = global.window[key]; + } catch (e) { + // NOTE: This is need for running tests on GitHub Actions CI, but causes + // failure on local builds due to this error: + // > Cannot set property navigator of # which has only a getter + if (!e.message.includes('Cannot set property navigator')) { + throw e; + } + } }); \ No newline at end of file