Skip to content

Commit

Permalink
make mocha run with ESM modules
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Aug 16, 2024
1 parent 2af2800 commit f1657b3
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
File renamed without changes.
7 changes: 3 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"name": "cryptomator-hub",
"version": "1.4.0",
"description": "Web-Frontend for Cryptomator Hub",
Expand All @@ -9,7 +10,7 @@
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"lint": "eslint -c .eslintrc.js",
"lint": "eslint -c .eslintrc.cjs",
"test": "nyc --reporter lcov mocha",
"serve": "vite preview",
"dist": "vue-tsc --noEmit && vite build --sourcemap --outDir=\"../backend/src/main/resources/META-INF/resources\" --emptyOutDir"
Expand All @@ -19,9 +20,7 @@
"test": "./test"
},
"mocha": {
"require": [
"ts-node/register"
],
"loader": "ts-node/esm",
"spec": "test/**/*.spec.ts",
"timeout": 60000
},
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion frontend/test/common/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import chaiAsPromised from 'chai-as-promised';
import { before, describe } from 'mocha';
import { base64, base64url } from 'rfc4648';
import { UnwrapKeyError, UserKeys, VaultKeys, getJwkThumbprint } from '../../src/common/crypto';
import { webcrypto } from 'node:crypto';

chaiUse(chaiAsPromised);

Expand Down Expand Up @@ -36,7 +37,7 @@ describe('crypto', () => {
before(async () => {
// since this test runs on Node, we need to replace window.crypto:
// @ts-ignore: global not defined (but will be available within Node)
Object.defineProperty(global, 'crypto', { value: require('node:crypto').webcrypto });
Object.defineProperty(global, 'crypto', { value: webcrypto });
// @ts-ignore: global not defined (but will be available within Node)
global.window = { crypto: global.crypto };

Expand Down
3 changes: 2 additions & 1 deletion frontend/test/common/jwe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { expect } from 'chai';
import { describe } from 'mocha';
import { base64url } from 'rfc4648';
import { ConcatKDF, ECDH_ES, ECDH_P384, JWEBuilder, JWEHeader, JWEParser, PBES2 } from '../../src/common/jwe';
import { webcrypto } from 'node:crypto';

describe('JWE', () => {
before(done => {
// since this test runs on Node, we need to replace window.crypto:
// @ts-ignore: global not defined (but will be available within Node)
Object.defineProperty(global, 'crypto', { value: require('node:crypto').webcrypto });
Object.defineProperty(global, 'crypto', { value: webcrypto });
// @ts-ignore: global not defined (but will be available within Node)
global.window = { crypto: global.crypto };
done();
Expand Down
3 changes: 2 additions & 1 deletion frontend/test/common/jwt.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { expect } from 'chai';
import { describe } from 'mocha';
import { JWT, JWTHeader } from '../../src/common/jwt';
import { webcrypto } from 'node:crypto';

describe('JWT', () => {
before(done => {
// since this test runs on Node, we need to replace window.crypto:
// @ts-ignore: global not defined (but will be available within Node)
Object.defineProperty(global, 'crypto', { value: require('node:crypto').webcrypto });
Object.defineProperty(global, 'crypto', { value: webcrypto });
// @ts-ignore: global not defined (but will be available within Node)
global.window = { crypto: global.crypto };
done();
Expand Down
7 changes: 3 additions & 4 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
"useUnknownInCatchVariables": false, // Workaround for `node_modules/miscreant/src/providers/webcrypto.ts:21:11 - error TS18046: 'e' is of type 'unknown'.`
},
"ts-node": {
"compilerOptions": {
"module": "CommonJS"
}
"esm": true,
"experimentalSpecifierResolution": "node"
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
"include": ["src/**/*.ts", "src/**/*.vue", "test/**/*.ts"]
}

0 comments on commit f1657b3

Please sign in to comment.