Skip to content

Commit 159d614

Browse files
committed
Fix errorSerializer fails to include stack trace in Firefox
Includes: - ESLint is now configured to lint tests in addition to source code - Added tests for WebExtensionService.getInitialAction - Fixed deprecated `.toBeCalledTimes` and `.toBeCalledWith` functions in tests - Fixed linting errors in tests WE2-1048 Signed-off-by: Tanel Metsar <taneltm@users.noreply.github.com>
1 parent 8c9030e commit 159d614

File tree

13 files changed

+615
-162
lines changed

13 files changed

+615
-162
lines changed

eslint.config.mjs

Lines changed: 85 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,106 @@
1-
// @ts-check
2-
import globals from "globals";
31
import eslint from "@eslint/js";
2+
import globals from "globals";
3+
import stylisticJs from "@stylistic/eslint-plugin-js";
4+
import stylisticTs from "@stylistic/eslint-plugin-ts";
45
import tseslint from "typescript-eslint";
5-
import stylisticTs from '@stylistic/eslint-plugin-ts';
6-
7-
export default tseslint.config(
8-
{
9-
extends: [
10-
eslint.configs.recommended,
11-
tseslint.configs.recommendedTypeChecked,
12-
tseslint.configs.stylisticTypeChecked,
13-
],
146

15-
files: ["src/**/*.ts"],
7+
const sharedOptions = {
8+
js: {
9+
files: ["**/*.{js,mjs}"],
1610

17-
ignores: [
18-
"dist/",
19-
"**/__tests__/**/*"
20-
],
21-
22-
plugins: {
23-
'@stylistic/ts': stylisticTs,
24-
'@typescript-eslint': tseslint.plugin,
11+
languageOptions: {
12+
sourceType: "module",
13+
14+
globals: {
15+
...globals.browser,
16+
...globals.node,
17+
...globals.es2021,
18+
...globals.webextensions,
19+
},
2520
},
21+
},
22+
23+
ts: {
24+
files: ["**/*.ts"],
2625

2726
languageOptions: {
2827
sourceType: "module",
28+
2929
globals: {
30-
...globals.browser,
31-
...globals.node,
32-
...globals.es2021,
33-
...globals.webextensions,
30+
...globals.browser,
31+
...globals.node,
32+
...globals.es2021,
33+
...globals.webextensions,
3434
},
35+
36+
parser: tseslint.parser,
37+
3538
parserOptions: {
36-
projectService: true,
39+
project: "./tsconfig.eslint.json",
3740
tsconfigRootDir: import.meta.dirname,
3841
},
3942
},
43+
},
44+
};
45+
46+
const overrides = {
47+
js: {
48+
...sharedOptions.js,
4049

50+
name: "web-eid/js/override",
51+
52+
plugins: { "@stylistic/js": stylisticJs },
53+
4154
rules: {
42-
"quotes": "error",
43-
"key-spacing": ["error", { "align": "value" }],
44-
"comma-dangle": ["error", "only-multiline"],
45-
"object-curly-spacing": ["error", "always"],
46-
"array-bracket-spacing": "error",
47-
"indent": ["error", 2, { "SwitchCase": 1 }],
48-
"sort-imports": ["error", { allowSeparatedGroups: true }],
55+
"sort-imports": ["error", { allowSeparatedGroups: true }],
56+
57+
"@stylistic/js/quotes": "error",
58+
"@stylistic/js/key-spacing": ["error", { "align": "value" }],
59+
"@stylistic/js/comma-dangle": ["error", "always-multiline"],
60+
"@stylistic/js/object-curly-spacing": ["error", "always"],
61+
"@stylistic/js/array-bracket-spacing": "error",
62+
"@stylistic/js/indent": ["error", 2, { "SwitchCase": 1 }],
63+
"@stylistic/js/semi": "error",
64+
},
65+
},
66+
67+
ts: {
68+
...sharedOptions.ts,
4969

50-
"@stylistic/ts/semi": "error",
70+
name: "web-eid/ts/override",
5171

72+
plugins: {
73+
"@typescript-eslint": tseslint.plugin,
74+
"@stylistic/ts": stylisticTs,
75+
},
76+
77+
rules: {
5278
"@typescript-eslint/array-type": ["error", { default: "generic" }],
79+
"@stylistic/ts/semi": "error",
5380
},
5481
},
55-
);
82+
};
83+
84+
export default [
85+
{ ignores: ["dist/", "node_modules/"] },
86+
87+
{
88+
name: "eslint/recommended",
89+
90+
...eslint.configs.recommended,
91+
...sharedOptions.js,
92+
},
93+
94+
...tseslint.configs.recommendedTypeChecked.map((recommended) => ({
95+
...recommended,
96+
...sharedOptions.ts,
97+
})),
98+
99+
...tseslint.configs.stylisticTypeChecked.map((stylistic) => ({
100+
...stylistic,
101+
...sharedOptions.ts,
102+
})),
103+
104+
overrides.js,
105+
overrides.ts,
106+
];

jest.config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

jest.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import('jest').Config} */
2+
const config = {
3+
preset: "ts-jest",
4+
testEnvironment: "jsdom",
5+
};
6+
7+
export default config;

package-lock.json

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"license": "MIT",
4040
"devDependencies": {
4141
"@rollup/plugin-terser": "^0.4.4",
42+
"@stylistic/eslint-plugin-js": "^3.1.0",
4243
"@stylistic/eslint-plugin-ts": "^3.0.1",
4344
"@types/jest": "^29.5.14",
4445
"eslint": "^9.19.0",

rollup.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from "path";
2-
import { fileURLToPath } from "url";
32

43
import cleanup from "rollup-plugin-cleanup";
54
import license from "rollup-plugin-license";

src/__tests__/web-eid-test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ describe("status", () => {
3939
it("should include library version with message to extension", async () => {
4040
jest.spyOn(window, "postMessage").mockImplementation();
4141

42-
try { await webeid.status(); } catch (e) { /* ignore */ }
42+
try { await webeid.status(); } catch { /* ignore */ }
4343

44-
expect(window.postMessage).toBeCalledTimes(1);
45-
expect(window.postMessage).toBeCalledWith(
44+
expect(window.postMessage).toHaveBeenCalledTimes(1);
45+
expect(window.postMessage).toHaveBeenCalledWith(
4646
{
4747
action: "web-eid:status",
4848
libraryVersion: process.env.npm_package_version,
@@ -93,10 +93,10 @@ describe("authenticate", () => {
9393

9494
const challengeNonce = "12345678901234567890123456789012345678901234";
9595

96-
try { await webeid.authenticate(challengeNonce, options); } catch (e) { /* ignore */ }
96+
try { await webeid.authenticate(challengeNonce, options); } catch { /* ignore */ }
9797

98-
expect(window.postMessage).toBeCalledTimes(1);
99-
expect(window.postMessage).toBeCalledWith(
98+
expect(window.postMessage).toHaveBeenCalledTimes(1);
99+
expect(window.postMessage).toHaveBeenCalledWith(
100100
{
101101
action: "web-eid:authenticate",
102102

@@ -117,10 +117,10 @@ describe("authenticate", () => {
117117

118118
const challengeNonce = "12345678901234567890123456789012345678901234";
119119

120-
try { await webeid.authenticate(challengeNonce, options); } catch (e) { /* ignore */ }
120+
try { await webeid.authenticate(challengeNonce, options); } catch { /* ignore */ }
121121

122-
expect(window.postMessage).toBeCalledTimes(1);
123-
expect(window.postMessage).toBeCalledWith(
122+
expect(window.postMessage).toHaveBeenCalledTimes(1);
123+
expect(window.postMessage).toHaveBeenCalledWith(
124124
{
125125
action: "web-eid:authenticate",
126126

@@ -150,10 +150,10 @@ describe("getSigningCertificate", () => {
150150

151151
const options: NativeAppOptions = { userInteractionTimeout: 1 };
152152

153-
try { await webeid.getSigningCertificate(options); } catch (e) { /* ignore */ }
153+
try { await webeid.getSigningCertificate(options); } catch { /* ignore */ }
154154

155-
expect(window.postMessage).toBeCalledTimes(1);
156-
expect(window.postMessage).toBeCalledWith(
155+
expect(window.postMessage).toHaveBeenCalledTimes(1);
156+
expect(window.postMessage).toHaveBeenCalledWith(
157157
{
158158
action: "web-eid:get-signing-certificate",
159159

@@ -174,10 +174,10 @@ describe("getSigningCertificate", () => {
174174
// Including userInteractionTimeout to speed up the test
175175
const options: NativeAppOptions = { userInteractionTimeout: 1, lang: "en" };
176176

177-
try { await webeid.getSigningCertificate(options); } catch (e) { /* ignore */ }
177+
try { await webeid.getSigningCertificate(options); } catch { /* ignore */ }
178178

179-
expect(window.postMessage).toBeCalledTimes(1);
180-
expect(window.postMessage).toBeCalledWith(
179+
expect(window.postMessage).toHaveBeenCalledTimes(1);
180+
expect(window.postMessage).toHaveBeenCalledWith(
181181
{
182182
action: "web-eid:get-signing-certificate",
183183

@@ -214,10 +214,10 @@ describe("sign", () => {
214214

215215
const options: NativeAppOptions = { userInteractionTimeout: 1 };
216216

217-
try { await webeid.sign(certificate, hash, hashFunction, options); } catch (e) { /* ignore */ }
217+
try { await webeid.sign(certificate, hash, hashFunction, options); } catch { /* ignore */ }
218218

219-
expect(window.postMessage).toBeCalledTimes(1);
220-
expect(window.postMessage).toBeCalledWith(
219+
expect(window.postMessage).toHaveBeenCalledTimes(1);
220+
expect(window.postMessage).toHaveBeenCalledWith(
221221
{
222222
action: "web-eid:sign",
223223

@@ -245,10 +245,10 @@ describe("sign", () => {
245245
// Including userInteractionTimeout to speed up the test
246246
const options: NativeAppOptions = { userInteractionTimeout: 1, lang: "en" };
247247

248-
try { await webeid.sign(certificate, hash, hashFunction, options); } catch (e) { /* ignore */ }
248+
try { await webeid.sign(certificate, hash, hashFunction, options); } catch { /* ignore */ }
249249

250-
expect(window.postMessage).toBeCalledTimes(1);
251-
expect(window.postMessage).toBeCalledWith(
250+
expect(window.postMessage).toHaveBeenCalledTimes(1);
251+
expect(window.postMessage).toHaveBeenCalledWith(
252252
{
253253
action: "web-eid:sign",
254254

src/errors/SerializedError.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import ErrorCode from "./ErrorCode";
2424

2525
export interface SerializedError {
26-
message: string;
27-
name: string;
28-
stack: string;
2926
code: ErrorCode;
30-
// ...any other fields that might be serialized
27+
message: string;
28+
name?: string;
29+
stack?: string;
30+
3131
[key: string]: unknown; // allow extra properties
3232
}

0 commit comments

Comments
 (0)