Skip to content

Commit 0be6c0e

Browse files
committed
fix!: Convert project to output ESM
1 parent e3953fb commit 0be6c0e

8 files changed

Lines changed: 43 additions & 43 deletions

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"url": "git+https://github.com/microcks/microcks-testcontainers-node.git"
1414
},
1515
"license": "Apache-2.0",
16-
"main": "build/index.js",
16+
"exports": "./build/index.js",
1717
"publishConfig": {
1818
"access": "public"
1919
},
@@ -46,6 +46,6 @@
4646
"build"
4747
],
4848
"engines": {
49-
"node": ">= 16"
49+
"node": ">= 18"
5050
}
5151
}

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
export * from "./microcks-container";
17-
export * from "./microcks-containers-ensemble";
18-
export * from "./microcks-async-minion-container";
16+
export * from "./microcks-container.js";
17+
export * from "./microcks-containers-ensemble.js";
18+
export * from "./microcks-async-minion-container.js";

src/microcks-async-minion-container.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
*/
1616

1717
import { AbstractStartedContainer, GenericContainer, StartedNetwork, StartedTestContainer, Wait, getContainerRuntimeClient } from "testcontainers";
18-
import { MicrocksContainer } from "./microcks-container";
18+
import { MicrocksContainer } from "./microcks-container.js";
1919

2020
export class MicrocksAsyncMinionContainer extends GenericContainer {
2121
static readonly MICROCKS_ASYNC_MINION_HTTP_PORT = 8081;
22-
22+
2323
private network: StartedNetwork;
2424
private extraProtocols: string = "";
25-
25+
2626
constructor(network: StartedNetwork, image = "quay.io/microcks/microcks-uber-async-minion:1.9.0") {
2727
super(image);
2828
this.network = network;

src/microcks-container.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import * as path from "path";
17-
import { dirname } from 'path';
18-
import { fileURLToPath } from 'url';
16+
import * as path from "node:path";
17+
import { dirname } from 'node:path';
18+
import { fileURLToPath } from 'node:url';
1919

2020
import { jest } from '@jest/globals'
2121
import { GenericContainer, Network, Wait } from "testcontainers";
@@ -38,7 +38,7 @@ describe("MicrocksContainer", () => {
3838
.withMainRemoteArtifacts(["https://raw.githubusercontent.com/microcks/microcks/master/samples/APIPastry-openapi.yaml"])
3939
.withSecondaryArtifacts([path.resolve(resourcesDir, "apipastries-postman-collection.json")])
4040
.start();
41-
41+
4242
// Test mock endpoints relative methods.
4343
let baseWsUrl = container.getSoapMockEndpoint("Pastries Service", "1.0");
4444
expect(container.getHttpEndpoint() + "/soap/Pastries Service/1.0").toBe(baseWsUrl);
@@ -127,7 +127,7 @@ describe("MicrocksContainer", () => {
127127
});
128128
// }
129129

130-
async function testInvocationsCheckingFunctionality(container: StartedMicrocksContainer,
130+
async function testInvocationsCheckingFunctionality(container: StartedMicrocksContainer,
131131
serviceName: string, serviceVersion: string, expectedCount: number) {
132132
expect(await container.verify(serviceName, serviceVersion)).toBe(true);
133133
expect(await container.getServiceInvocationsCount(serviceName, serviceVersion)).toBe(expectedCount)
@@ -151,7 +151,7 @@ describe("MicrocksContainer", () => {
151151
.start();
152152

153153
await container.importAsMainArtifact(path.resolve(resourcesDir, "apipastries-openapi.yaml"));
154-
154+
155155
var testRequest: TestRequest = {
156156
serviceId: "API Pastries:0.0.1",
157157
runnerType: TestRunnerType.OPEN_API_SCHEMA,
@@ -250,4 +250,4 @@ describe("MicrocksContainer", () => {
250250
await network.stop();
251251
});
252252
// }
253-
});
253+
});

src/microcks-container.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import * as path from "path";
17-
import { readFile, stat } from "fs/promises";
16+
import * as path from "node:path";
17+
import { readFile, stat } from "node:fs/promises";
1818
import { AbstractStartedContainer, GenericContainer, StartedTestContainer, Wait } from "testcontainers";
1919

2020
export class MicrocksContainer extends GenericContainer {
2121
static readonly MICROCKS_HTTP_PORT = 8080;
2222
static readonly MICROCKS_GRPC_PORT = 9090;
23-
23+
2424
private snapshots: string[] = [];
2525
private mainArtifacts: string[] = [];
2626
private secondaryArtifacts: string[] = [];
@@ -120,7 +120,7 @@ export class MicrocksContainer extends GenericContainer {
120120
for (let i=0; i<this.secondaryRemoteArtifacts.length; i++) {
121121
await startedContainer.downloadAsSecondaryArtifact(this.secondaryRemoteArtifacts[i]);
122122
}
123-
// Import artifacts declared in configuration.
123+
// Import artifacts declared in configuration.
124124
for (let i=0; i<this.mainArtifacts.length; i++) {
125125
await startedContainer.importAsMainArtifact(this.mainArtifacts[i]);
126126
}
@@ -386,7 +386,7 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
386386
public getValidatingRestMockEndpointPath(service: string, version: string): string {
387387
return `/rest-valid/${service}/${version}`;
388388
}
389-
389+
390390
/**
391391
* Get the exposed mock endpoint for a GraphQL API.
392392
* @param {String} service The name of Service/API
@@ -426,7 +426,7 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
426426
}
427427

428428
/**
429-
* Import an artifact as a secondary one within the Microcks container.
429+
* Import an artifact as a secondary one within the Microcks container.
430430
* @param {String} artifactPath The file path to artifact (OpenAPI, Postman collection, Protobuf, GraphQL schema, ...)
431431
* @returns Success or error via Promise
432432
*/
@@ -597,7 +597,7 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
597597
return invocationStats.dailyCount;
598598
}
599599

600-
600+
601601
private async importArtifact(artifactPath: string, mainArtifact: boolean): Promise<void> {
602602
const isFile = await this.isFile(artifactPath);
603603
if (!isFile) {
@@ -703,7 +703,7 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
703703

704704
// Tto avoid race condition issue while Microcks server is processing metrics asynchronously.
705705
await this.wait(100);
706-
706+
707707
// Request the daily statistics.
708708
const response = await fetch(endpointUrl, {
709709
method: 'GET',
@@ -719,7 +719,7 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
719719
throw new Error("Couldn't get service's invocations on Microcks. Please check Microcks container logs");
720720
}
721721

722-
private async isFile(path: string): Promise<boolean> {
722+
private async isFile(path: string): Promise<boolean> {
723723
const stats = await stat(path);
724724
return stats.isFile()
725725
}

src/microcks-containers-ensemble.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import * as path from "path";
17-
import { dirname } from 'path';
18-
import { fileURLToPath } from 'url';
16+
import * as path from "node:path";
17+
import { dirname } from 'node:path';
18+
import { fileURLToPath } from 'node:url';
1919

2020
import { jest } from '@jest/globals'
2121
import { CreateQueueCommand, ListQueuesCommand, ReceiveMessageCommand, SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
2222
import { GenericContainer, Network, Wait } from "testcontainers";
2323
import { LocalstackContainer } from "@testcontainers/localstack";
2424
import { RabbitMQContainer } from "@testcontainers/rabbitmq";
25-
import { MicrocksContainersEnsemble } from "./microcks-containers-ensemble";
26-
import { TestRequest, TestResult, TestRunnerType } from "./microcks-container";
25+
import { MicrocksContainersEnsemble } from "./microcks-containers-ensemble.js";
26+
import { TestRequest, TestResult, TestRunnerType } from "./microcks-container.js";
2727
import { WebSocket } from "ws";
28-
import mqtt from "mqtt";
28+
import mqtt from "mqtt";
2929
import amqp from "amqplib";
3030

3131
describe("MicrocksContainersEnsemble", () => {
@@ -143,7 +143,7 @@ describe("MicrocksContainersEnsemble", () => {
143143
let wsEndpoint = ensemble.getAsyncMinionContainer()?.getWSMockEndpoint("Pastry orders API", "0.1.0", "SUBSCRIBE pastry/orders");
144144
let expectedMessage = "{\"id\":\"4dab240d-7847-4e25-8ef3-1530687650c8\",\"customerId\":\"fe1088b3-9f30-4dc1-a93d-7b74f0a072b9\",\"status\":\"VALIDATED\",\"productQuantities\":[{\"quantity\":2,\"pastryName\":\"Croissant\"},{\"quantity\":1,\"pastryName\":\"Millefeuille\"}]}";
145145

146-
const ws = new WebSocket(wsEndpoint as string);
146+
const ws = new WebSocket(wsEndpoint as string);
147147
ws.on('error', console.error);
148148
ws.on('message', function message(data) {
149149
messages.push(data.toString());
@@ -199,7 +199,7 @@ describe("MicrocksContainersEnsemble", () => {
199199
expect(testResult.testCaseResults[0].testStepResults[0].message).toContain("object has missing required properties");
200200

201201
// Retrieve event messages for the failing test case.
202-
const events = await ensemble.getMicrocksContainer().getEventMessagesForTestCase(testResult,
202+
const events = await ensemble.getMicrocksContainer().getEventMessagesForTestCase(testResult,
203203
"SUBSCRIBE pastry/orders");
204204

205205
// We should have at least 1 event.
@@ -326,7 +326,7 @@ describe("MicrocksContainersEnsemble", () => {
326326
//await channel.checkExchange(amqpDestination as string);
327327
await channel.assertQueue('microcks-test', { durable: false });
328328
await channel.bindQueue('microcks-test', amqpDestination as string, '');
329-
329+
330330
channel.consume('microcks-test', (msg: any) => {
331331
if (msg !== null) {
332332
messages.push(msg.content.toString());
@@ -391,7 +391,7 @@ describe("MicrocksContainersEnsemble", () => {
391391
endpointOverride: 'http://localstack:4566'
392392
})
393393
.start();
394-
394+
395395
// Initialize messages list and connect to mock endpoint.
396396
let messages: string[] = [];
397397
let sqsEndpoint = ensemble.getAsyncMinionContainer()?.getAmazonSQSMockQueue("Pastry orders API", "0.1.0", "SUBSCRIBE pastry/orders");

src/microcks-containers-ensemble.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
* limitations under the License.
1515
*/
1616
import { GenericContainer, StartedNetwork, StartedTestContainer, StopOptions, Wait } from "testcontainers";
17-
import { MicrocksContainer, Secret, StartedMicrocksContainer } from "./microcks-container";
18-
import {
19-
AmazonServiceConnection, GenericConnection, KafkaConnection,
20-
MicrocksAsyncMinionContainer, StartedMicrocksAsyncMinionContainer
21-
} from "./microcks-async-minion-container";
17+
import { MicrocksContainer, Secret, StartedMicrocksContainer } from "./microcks-container.js";
18+
import {
19+
AmazonServiceConnection, GenericConnection, KafkaConnection,
20+
MicrocksAsyncMinionContainer, StartedMicrocksAsyncMinionContainer
21+
} from "./microcks-async-minion-container.js";
2222

2323
export class MicrocksContainersEnsemble {
2424
static readonly MICROCKS_CONTAINER_ALIAS = "microcks";
@@ -38,9 +38,9 @@ export class MicrocksContainersEnsemble {
3838
.withNetworkAliases(MicrocksContainersEnsemble.MICROCKS_CONTAINER_ALIAS)
3939
.withEnvironment({
4040
POSTMAN_RUNNER_URL: "http://" + MicrocksContainersEnsemble.POSTMAN_CONTAINER_ALIAS + ":3000",
41-
TEST_CALLBACK_URL: "http://" + MicrocksContainersEnsemble.MICROCKS_CONTAINER_ALIAS
41+
TEST_CALLBACK_URL: "http://" + MicrocksContainersEnsemble.MICROCKS_CONTAINER_ALIAS
4242
+ ":" + MicrocksContainer.MICROCKS_HTTP_PORT,
43-
ASYNC_MINION_URL: "http://" + MicrocksContainersEnsemble.MICROCKS_ASYNC_MINION_CONTAINER_ALIAS
43+
ASYNC_MINION_URL: "http://" + MicrocksContainersEnsemble.MICROCKS_ASYNC_MINION_CONTAINER_ALIAS
4444
+ ":" + MicrocksAsyncMinionContainer.MICROCKS_ASYNC_MINION_HTTP_PORT,
4545
});
4646
}

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"compilerOptions": {
33
"incremental": true,
44
"target": "es2022",
5-
"module": "commonjs",
5+
"module": "node16",
66
"declaration": true,
77
"sourceMap": true,
88
"strict": true,
9-
"moduleResolution": "node",
9+
"moduleResolution": "node16",
1010
"esModuleInterop": true,
1111
"skipLibCheck": true,
1212
"forceConsistentCasingInFileNames": true,

0 commit comments

Comments
 (0)