Skip to content

Commit 7e961f4

Browse files
working!
1 parent 2361c75 commit 7e961f4

File tree

11 files changed

+51
-42
lines changed

11 files changed

+51
-42
lines changed

.mocharc.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
"require": [
44
"source-map-support/register",
55
"ts-node/register",
6-
"test/tools/chai-addons.js"
6+
"test/tools/chai-addons.mts"
77
],
88
"extension": [
9-
"ts"
9+
"mts"
10+
],
11+
"node-option": [
12+
"expose-gc",
13+
"experimental-specifier-resolution=node",
14+
"loader=ts-node/esm"
1015
],
1116
"recursive": true,
1217
"failZero": true,
File renamed without changes.

src/index.ts renamed to src/index.mts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { cryptoCallbacks } from './crypto_callbacks';
1+
import { createRequire } from 'module';
2+
import { cryptoCallbacks } from './crypto_callbacks.mjs';
23
export { cryptoCallbacks };
34

45
function load() {
6+
const require = createRequire(import.meta.url);
57
try {
68
return require('../build/Release/mongocrypt.node');
79
} catch {
@@ -74,7 +76,7 @@ type MongoCryptConstructorOptions = {
7476
};
7577

7678
export interface MongoCryptConstructor {
77-
new (options: MongoCryptConstructorOptions): MongoCrypt;
79+
new(options: MongoCryptConstructorOptions): MongoCrypt;
7880
libmongocryptVersion: string;
7981
}
8082

@@ -136,6 +138,6 @@ export const MongoCrypt: MongoCryptConstructor = class MongoCrypt extends mc.Mon
136138

137139
/** exported for testing only. */
138140
interface MongoCryptContextCtor {
139-
new (): MongoCryptContext;
141+
new(): MongoCryptContext;
140142
}
141143
export const MongoCryptContextCtor: MongoCryptContextCtor = mc.MongoCryptContextCtor;

test/tools/chai-addons.js

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

test/tools/chai-addons.mts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as chai from 'chai';
2+
import sinonChai from 'sinon-chai';
3+
import * as chaiSubset from 'chai-subset';
4+
5+
chai.use(sinonChai);
6+
// @ts-expect-error
7+
chai.use(chaiSubset.default);
8+
9+
chai.config.truncateThreshold = 0;

test/tsconfig.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"strict": false,
55
"allowJs": false,
66
"checkJs": false,
7+
"types": [
8+
"mocha"
9+
]
710
},
811
"include": [
9-
"../node_modules/@types/mocha/index.d.ts",
10-
"./**/*.ts"
12+
"./**/*.mts"
1113
]
12-
}
14+
}

test/unit/bindings.test.ts renamed to test/unit/bindings.test.mts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { MongoCrypt, MongoCryptContext, MongoCryptContextCtor } from '../../src';
2+
import { MongoCrypt, MongoCryptContext, MongoCryptContextCtor } from '../../src/index.mjs'
33
import { serialize, Binary, Long } from 'bson';
44
import * as crypto from 'crypto';
55

@@ -19,15 +19,15 @@ describe('MongoCryptConstructor', () => {
1919
const mc = new MongoCrypt({
2020
kmsProviders: serialize({ aws: {} }),
2121
cryptoCallbacks: {
22-
aes256CbcEncryptHook: () => {},
23-
aes256CbcDecryptHook: () => {},
24-
aes256CtrEncryptHook: () => {},
25-
aes256CtrDecryptHook: () => {},
22+
aes256CbcEncryptHook: () => { },
23+
aes256CbcDecryptHook: () => { },
24+
aes256CtrEncryptHook: () => { },
25+
aes256CtrDecryptHook: () => { },
2626
randomHook,
27-
hmacSha512Hook: () => {},
28-
hmacSha256Hook: () => {},
29-
sha256Hook: () => {},
30-
signRsaSha256Hook: () => {}
27+
hmacSha512Hook: () => { },
28+
hmacSha256Hook: () => { },
29+
sha256Hook: () => { },
30+
signRsaSha256Hook: () => { }
3131
}
3232
});
3333

@@ -41,17 +41,17 @@ describe('MongoCryptConstructor', () => {
4141
kmsProviders: serialize({ aws: {} }),
4242
schemaMap: serialize({}),
4343
encryptedFieldsMap: serialize({}),
44-
logger: () => {},
44+
logger: () => { },
4545
cryptoCallbacks: {
46-
aes256CbcEncryptHook: () => {},
47-
aes256CbcDecryptHook: () => {},
48-
aes256CtrEncryptHook: () => {},
49-
aes256CtrDecryptHook: () => {},
46+
aes256CbcEncryptHook: () => { },
47+
aes256CbcDecryptHook: () => { },
48+
aes256CtrEncryptHook: () => { },
49+
aes256CtrDecryptHook: () => { },
5050
randomHook,
51-
hmacSha512Hook: () => {},
52-
hmacSha256Hook: () => {},
53-
sha256Hook: () => {},
54-
signRsaSha256Hook: () => {}
51+
hmacSha512Hook: () => { },
52+
hmacSha256Hook: () => { },
53+
sha256Hook: () => { },
54+
signRsaSha256Hook: () => { }
5555
},
5656

5757
bypassQueryAnalysis: false

test/unit/crypto.test.ts renamed to test/unit/crypto.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'node:path';
44
import * as fs from 'node:fs';
55
import * as sinon from 'sinon';
66
import { EJSON, BSON, Binary } from 'bson';
7-
import { MongoCrypt, MongoCryptConstructor, cryptoCallbacks } from '../../src';
7+
import { MongoCrypt, MongoCryptConstructor, cryptoCallbacks } from '../../src/index.mjs';
88
import { expect } from 'chai';
99

1010
const NEED_MONGO_KEYS = 3;
@@ -23,7 +23,7 @@ const LOCAL_KEY = new Uint8Array([
2323
const kmsProviders = { local: { key: LOCAL_KEY } };
2424
const algorithm = 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic';
2525
const keyDocument = EJSON.parse(
26-
fs.readFileSync(path.join(__dirname, '..', 'benchmarks', 'keyDocument.json'), 'utf8'),
26+
fs.readFileSync(path.join(import.meta.dirname, '..', 'benchmarks', 'keyDocument.json'), 'utf8'),
2727
{
2828
relaxed: false
2929
}

test/unit/index.test.ts renamed to test/unit/index.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import * as bindings from '../../src/index';
2+
import * as bindings from '../../src/index.mjs';
33

44
describe('index.ts', () => {
55
it('only has three exports', () => {
File renamed without changes.

tsconfig.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
"strict": true,
66
"alwaysStrict": true,
77
"target": "ES2020",
8-
"module": "commonJS",
8+
"module": "esnext",
99
"moduleResolution": "node",
1010
"skipLibCheck": true,
1111
"erasableSyntaxOnly": true,
1212
"lib": [
13-
"es2020", "es2021.WeakRef"
13+
"es2020",
14+
"es2021.WeakRef"
1415
],
1516
// We don't make use of tslib helpers, all syntax used is supported by target engine
1617
"importHelpers": false,
@@ -43,4 +44,4 @@
4344
"include": [
4445
"src/**/*"
4546
]
46-
}
47+
}

0 commit comments

Comments
 (0)