Skip to content

Commit

Permalink
chore(deps): bump dependencies
Browse files Browse the repository at this point in the history
- fix promises test issue
- update got to 11.8.5 & fix changes
- update chalk to 4.1.2 (latest commonjs version)
- update eslint to latest node@10 compatible version
- update prettier version & fix code format
- update jest to 27.5.1

related to camunda/camunda-bpm-platform#2801
  • Loading branch information
danielkelemen committed Nov 15, 2022
1 parent ec96abc commit 4b65a95
Show file tree
Hide file tree
Showing 30 changed files with 6,104 additions and 9,449 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
test/
__mocks__/
examples/
.idea/
coverage/
.github/
4 changes: 2 additions & 2 deletions examples/granting-loans/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
const {
Client,
logger,
Variables
Variables,
} = require("camunda-external-task-client-js");

// configuration for the Client:
// - 'baseUrl': url to the Process Engine
// - 'logger': utility to automatically log important events
const config = {
baseUrl: "http://localhost:8080/engine-rest",
use: logger
use: logger,
};

// create a Client instance with custom configuration
Expand Down
6 changes: 3 additions & 3 deletions examples/order/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ const {
Client,
logger,
Variables,
File
File,
} = require("camunda-external-task-client-js");

// configuration for the Client:
// - 'baseUrl': url to the Process Engine
// - 'logger': utility to automatically log important events
const config = {
baseUrl: "http://localhost:8080/engine-rest",
use: logger
use: logger,
};

// create a Client instance with custom configuration
const client = new Client(config);

// susbscribe to the topic: 'invoiceCreator'
client.subscribe("invoiceCreator", async function({ task, taskService }) {
client.subscribe("invoiceCreator", async function ({ task, taskService }) {
// Put your business logic
// complete the task
const date = new Date();
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ module.exports = {
BasicAuthInterceptor: require("./lib/BasicAuthInterceptor"),
KeycloakAuthInterceptor: require("./lib/KeycloakAuthInterceptor"),
Variables: require("./lib/Variables"),
File: require("./lib/File")
File: require("./lib/File"),
};
4 changes: 2 additions & 2 deletions lib/BasicAuthInterceptor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ describe("BasicAuthInterceptor", () => {
// given
const basicAuthInterceptor = new BasicAuthInterceptor({
username: "some username",
password: "some password"
password: "some password",
});
const config = { key: "some value" };
const headers = basicAuthInterceptor(config);

//then
// then
expect(headers).toMatchSnapshot();
});
});
22 changes: 11 additions & 11 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ const {
ALREADY_REGISTERED,
MISSING_HANDLER,
WRONG_INTERCEPTOR,
WRONG_MIDDLEWARES
WRONG_MIDDLEWARES,
} = require("./__internal/errors");

const {
isFunction,
isArrayOfFunctions,
isUndefinedOrNull
isUndefinedOrNull,
} = require("./__internal/utils");

const defaultOptions = {
Expand All @@ -41,7 +41,7 @@ const defaultOptions = {
usePriority: true,
interval: 300,
lockDuration: 50000,
autoPoll: true
autoPoll: true,
};

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ class Client extends events {
this.taskService = new TaskService(this, this.engineService);

if (this.options.use) {
this.options.use.forEach(f => f(this));
this.options.use.forEach((f) => f(this));
}

if (this.options.autoPoll) {
Expand Down Expand Up @@ -155,7 +155,7 @@ class Client extends events {
usePriority,
interval,
asyncResponseTimeout,
maxParallelExecutions
maxParallelExecutions,
} = this.options;

const requiredTasksCount = isUndefinedOrNull(maxParallelExecutions)
Expand All @@ -169,7 +169,7 @@ class Client extends events {
// setup polling options
let pollingOptions = {
maxTasks: requiredTasksCount,
usePriority: usePriority
usePriority: usePriority,
};
if (asyncResponseTimeout) {
pollingOptions = { ...pollingOptions, asyncResponseTimeout };
Expand All @@ -196,8 +196,8 @@ class Client extends events {
processVariables,
tenantIdIn,
withoutTenantId,
localVariables
}
localVariables,
},
]) => {
let topic = { topicName, lockDuration };

Expand Down Expand Up @@ -277,7 +277,7 @@ class Client extends events {
throw new Error(ALREADY_REGISTERED);
}

//handles the case if there is no options being
// handles the case if there is no options being
if (typeof customOptions === "function") {
handler = customOptions;
customOptions = null;
Expand All @@ -295,7 +295,7 @@ class Client extends events {
handler,
unsubscribe,
lockDuration,
...customOptions
...customOptions,
};
topicSubscriptions[topic] = topicSubscription;
this.emit("subscribe", topic, topicSubscription);
Expand All @@ -312,7 +312,7 @@ class Client extends events {
const variables = new Variables(task.variables, {
readOnly: true,
processInstanceId: task.processInstanceId,
engineService: this.engineService
engineService: this.engineService,
});

this.activeTasksCount++;
Expand Down
80 changes: 41 additions & 39 deletions lib/Client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ const {
MISSING_BASE_URL,
ALREADY_REGISTERED,
MISSING_HANDLER,
WRONG_MIDDLEWARES
WRONG_MIDDLEWARES,
} = require("./__internal/errors");

// workaround for https://github.com/facebook/jest/issues/2157
const flushPromises = () =>
new Promise(jest.requireActual("timers").setImmediate);
const advanceTimersByTime = async (msToRun) => {
await flushPromises();
return jest.advanceTimersByTime(msToRun);
};

jest.mock("got");
jest.mock("../lib/Variables");

Expand All @@ -35,7 +43,7 @@ const customClientOptions = {
workerId: "foobarId",
maxTasks: 3,
interval: 100,
lockDuration: 30000
lockDuration: 30000,
};

describe("Client", () => {
Expand All @@ -54,29 +62,29 @@ describe("Client", () => {
// when
client.start();

//then
// then
expect(pollSpy).toHaveBeenCalled();
});

test("should call itself again after timeout when there are no topic subscriptions", () => {
test("should call itself again after timeout when there are no topic subscriptions", async () => {
// when
client.start();
jest.advanceTimersByTime(customClientOptions.interval);
await advanceTimersByTime(customClientOptions.interval);

// then
expect(pollSpy).toHaveBeenCalledTimes(2);
});

test("should not call itself again after timeout when there are registered client", () => {
//given
test("should not call itself again after timeout when there are registered client", async () => {
// given
client.subscribe("foo", () => {});

// when
client.start();
jest.advanceTimersByTime(customClientOptions.interval);
await advanceTimersByTime(customClientOptions.interval);

// then
expect(pollSpy).toHaveBeenCalledTimes(1);
expect(pollSpy).toHaveBeenCalledTimes(2);
});

test("should fetchAndLock and then call itself again when there are registered client", async () => {
Expand All @@ -86,24 +94,22 @@ describe("Client", () => {

// when
client.start();
jest.advanceTimersByTime(customClientOptions.interval);
await advanceTimersByTime(customClientOptions.interval);

//then
// then
expect(fetchAndLockSpy).toBeCalled();
await engineService.fetchAndLock({});
jest.advanceTimersByTime(customClientOptions.interval);
expect(pollSpy).toHaveBeenCalledTimes(2);
});
});

describe("when autoPoll is true", () => {
it("should call itself automatically when autoPoll is true", () => {
it("should call itself automatically when autoPoll is true", async () => {
// given
const client = new Client({ ...customClientOptions, autoPoll: true });
const pollSpy = jest.spyOn(client, "poll");

//when
jest.advanceTimersByTime(2 * customClientOptions.interval);
// when
await advanceTimersByTime(2 * customClientOptions.interval);

// then
expect(pollSpy).toHaveBeenCalledTimes(1);
Expand All @@ -114,11 +120,11 @@ describe("Client", () => {
test("should use Priority by default", () => {
const client = new Client({
...customClientOptions,
autoPoll: false
autoPoll: false,
});

const fetchSpy = jest.spyOn(client.engineService, "fetchAndLock");
client.subscribe("foo", {}, function() {});
client.subscribe("foo", {}, function () {});
client.start();

expect(fetchSpy).toHaveBeenCalled();
Expand All @@ -130,11 +136,11 @@ describe("Client", () => {
const client = new Client({
...customClientOptions,
usePriority: false,
autoPoll: false
autoPoll: false,
});

const fetchSpy = jest.spyOn(client.engineService, "fetchAndLock");
client.subscribe("foo", {}, function() {});
client.subscribe("foo", {}, function () {});
client.start();

expect(fetchSpy).toHaveBeenCalled();
Expand All @@ -149,7 +155,7 @@ describe("Client", () => {
const client = new Client({
...customClientOptions,
autoPoll: false,
maxParallelExecutions: 1
maxParallelExecutions: 1,
});
const pollSpy = jest.spyOn(client, "poll");

Expand All @@ -159,46 +165,42 @@ describe("Client", () => {
.mockResolvedValue([{ topicName: "foo", variables: {} }]);

client.subscribe("foo", async () => {
await new Promise(resolve =>
await new Promise((resolve) =>
setTimeout(resolve, customClientOptions.interval)
);
await new Promise(resolve =>
await new Promise((resolve) =>
setTimeout(resolve, 0.5 * customClientOptions.interval)
);
});

// when
client.start();

//then
// then
expect(engineService.fetchAndLock).toBeCalled();

await engineService.get();
jest.advanceTimersByTime(customClientOptions.interval);
await advanceTimersByTime(customClientOptions.interval);

expect(pollSpy).toHaveBeenCalledTimes(2);
expect(engineService.fetchAndLock).toHaveBeenCalledTimes(1);

await engineService.get();
jest.advanceTimersByTime(0.5 * customClientOptions.interval);
await engineService.get();
jest.advanceTimersByTime(0.5 * customClientOptions.interval);
await advanceTimersByTime(customClientOptions.interval);

expect(pollSpy).toHaveBeenCalledTimes(3);
expect(engineService.fetchAndLock).toHaveBeenCalledTimes(1);
});
});

describe("stop", () => {
it("should stop polling", () => {
it("should stop polling", async () => {
// given: we advance time twice then call stop
const client = new Client(customClientOptions);
jest.advanceTimersByTime(2 * customClientOptions.interval);
await advanceTimersByTime(2 * customClientOptions.interval);
client.stop();
const pollSpy = jest.spyOn(client, "poll");

// when
jest.advanceTimersByTime(2 * customClientOptions.interval);
await advanceTimersByTime(2 * customClientOptions.interval);

// then
expect(pollSpy).not.toHaveBeenCalled();
Expand Down Expand Up @@ -228,7 +230,7 @@ describe("Client", () => {
processDefinitionVersionTag: "versionTag",
tenantIdIn: ["tenantId"],
withoutTenantId: true,
localVariables: true
localVariables: true,
};
});

Expand Down Expand Up @@ -456,23 +458,23 @@ describe("Client", () => {
});

it("should accept middleware function", () => {
//givena
// givena
const middleware = jest.fn();
const options = { ...customClientOptions, use: middleware };
const client = new Client(options);

//then
// then
expect(middleware).toBeCalledWith(client);
});

it("should accept middlewares array", () => {
//given
// given
const middlewares = [jest.fn(), jest.fn()];
const options = { ...customClientOptions, use: middlewares };
const client = new Client(options);

//then
middlewares.forEach(middleware =>
// then
middlewares.forEach((middleware) =>
expect(middleware).toBeCalledWith(client)
);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class File {
return {
type: "file",
value: this.content.toString("base64"),
valueInfo
valueInfo,
};
}
}
Expand Down
Loading

0 comments on commit 4b65a95

Please sign in to comment.