Skip to content

Commit

Permalink
Merge pull request #791 from SquirrelCorporation/chore-vitest-3
Browse files Browse the repository at this point in the history
[CHORE] Ensure async usage in test assertions and update dependencies
  • Loading branch information
SquirrelDeveloper authored Feb 25, 2025
2 parents 2dba31f + 68664ed commit 7cc4954
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 237 deletions.
412 changes: 206 additions & 206 deletions server/package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dev": "pwd && nodemon",
"start": "npm run build-shared && npm run build && cross-env NODE_ENV=production node dist/index.js",
"build": "tsc",
"test": "vitest --disable-console-intercept --reporter=basic ",
"test": "vitest --disable-console-intercept",
"test:python:install": "PIP_BREAK_SYSTEM_PACKAGES=1 pip install -r ./src/ansible/requirements.txt",
"test:python": "npm run test:python:install && npm run test:python:run",
"test:python:run": "cd ./src/ansible && python3 -m unittest discover -s . -p \"*.py\"",
Expand Down Expand Up @@ -74,7 +74,7 @@
"@eslint/js": "^9.21.0",
"@types/bcrypt": "^5.0.2",
"@types/cookie-parser": "^1.4.8",
"@types/dockerode": "^3.3.34",
"@types/dockerode": "^3.3.35",
"@types/dockerode-compose": "^1.4.1",
"@types/fs-extra": "^11.0.4",
"@types/jsonwebtoken": "^9.0.9",
Expand All @@ -92,22 +92,22 @@
"@types/supertest": "^6.0.2",
"@types/uuid": "^10.0.0",
"@types/multer": "^1.4.12",
"@typescript-eslint/eslint-plugin": "^8.24.1",
"@vitest/coverage-v8": "^3.0.6",
"@typescript-eslint/eslint-plugin": "^8.25.0",
"@vitest/coverage-v8": "^3.0.7",
"eslint": "^9.21.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-import-x": "^4.6.1",
"@stylistic/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^8.24.1",
"@typescript-eslint/parser": "^8.25.0",
"globals": "^16.0.0",
"mongodb-memory-server": "^10.1.4",
"node-mocks-http": "^1.16.2",
"prettier": "^3.5.2",
"supertest": "^7.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.7.3",
"vitest": "^3.0.6",
"vitest": "^3.0.7",
"@types/js-yaml": "^4.0.9",
"@types/express": "^5.0.0",
"memfs": "^4.17.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('SSHCredentialsHelper', () => {
deviceAuth.authType = SsmAnsible.SSHType.KeyBased;
const result = SSHCredentialsHelper.getDockerSshConnectionOptions(device, deviceAuth);

expect(result).resolves.toMatchObject({
await expect(result).resolves.toMatchObject({
protocol: 'ssh',
port: 22,
username: 'apiuser',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import { Automations } from 'ssm-shared-lib';
import AutomationComponent from '../../../../modules/automations/AutomationComponent';
import CronTriggerComponent from '../../../../modules/automations/triggers/CronTriggerComponent';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import DockerActionComponent from '../../../../modules/automations/actions/DockerActionComponent';
import PlaybookActionComponent from '../../../../modules/automations/actions/PlaybookActionComponent';
import AutomationComponent from '../../../../modules/automations/AutomationComponent';
import CronTriggerComponent from '../../../../modules/automations/triggers/CronTriggerComponent';

vi.mock('./../../../../modules/automations/triggers/CronTriggerComponent');
vi.mock('./../../../../modules/automations/actions/DockerActionComponent');
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('init method of AutomationComponent class', () => {
test('should throw error for unknown trigger type', async () => {
// @ts-expect-error provoke error
automation.automationChain.trigger = 'Unknown';
expect(automation.init()).rejects.toThrow('Unknown trigger type');
await expect(automation.init()).rejects.toThrow('Unknown trigger type');
});

test('should properly initialize actions for docker action type', async () => {
Expand All @@ -68,6 +68,6 @@ describe('init method of AutomationComponent class', () => {
test('should throw error for unknown action type', async () => {
// @ts-expect-error provoke error
automation.automationChain.actions[0].action = 'Unknown';
expect(automation.init()).rejects.toThrow('Unknown action type');
await expect(automation.init()).rejects.toThrow('Unknown action type');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('DockerActionComponent', () => {
);

// An error should be thrown if the container can't be retrieved
expect(dockerActionComponent.executeAction()).resolves.toBeUndefined();
await expect(dockerActionComponent.executeAction()).resolves.toBeUndefined();
expect(ContainerUseCases.performDockerAction).not.toHaveBeenCalled();
});

Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/unit-tests/modules/docker/Acr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ describe('testing Acr Registry', () => {
});
});

test('authenticate should add basic auth', () => {
test('authenticate should add basic auth', async () => {
// @ts-expect-error partial type
expect(acr.authenticate(undefined, { headers: {} })).resolves.toEqual({
await expect(acr.authenticate(undefined, { headers: {} })).resolves.toEqual({
headers: {
Authorization: 'Basic Y2xpZW50aWQ6Y2xpZW50c2VjcmV0',
},
Expand Down
8 changes: 4 additions & 4 deletions server/src/tests/unit-tests/modules/docker/Component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@ describe('testing Component', () => {
expect(spyInit).toHaveBeenCalledTimes(1);
});

test('register should not call init when validateConfiguration fails', () => {
test('register should not call init when validateConfiguration fails', async () => {
const component = new Component();
component.validateConfiguration = () => {
throw new Error('validation failed');
};
const spyInit = vi.spyOn(component, 'init');
// @ts-expect-error partial type
expect(component.register('id', 'type', 'name', { x: 'x' })).rejects.toThrowError(
await expect(component.register('id', 'type', 'name', { x: 'x' })).rejects.toThrowError(
'validation failed',
);
expect(spyInit).toHaveBeenCalledTimes(0);
});

test('register should throw when init fails', () => {
test('register should throw when init fails', async () => {
const component = new Component();
component.init = () => {
throw new Error('init failed');
};
// @ts-expect-error partial type
expect(component.register('id', 'type', 'name', { x: 'x' })).rejects.toThrowError(
await expect(component.register('id', 'type', 'name', { x: 'x' })).rejects.toThrowError(
'init failed',
);
});
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/unit-tests/modules/docker/Ecr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ describe('testing ECR Registry', () => {
});
});

test('authenticate should call ecr auth endpoint', () => {
test('authenticate should call ecr auth endpoint', async () => {
// @ts-expect-error partial type
expect(ecr.authenticate(undefined, { headers: {} })).resolves.toEqual({
await expect(ecr.authenticate(undefined, { headers: {} })).resolves.toEqual({
headers: {
Authorization: 'Basic xxxxx',
},
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/unit-tests/modules/docker/Gcr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ describe('testing GCR Registry', () => {
});
});

test('authenticate should call ecr auth endpoint', () => {
test('authenticate should call ecr auth endpoint', async () => {
// @ts-expect-error partial type
expect(gcr.authenticate({}, { headers: {} })).resolves.toEqual({
await expect(gcr.authenticate({}, { headers: {} })).resolves.toEqual({
headers: {
Authorization: 'Bearer xxxxx',
},
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/unit-tests/modules/docker/Ghcr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ describe('testing GHCR Registry', () => {
});
});

test('authenticate should populate header with base64 bearer', () => {
test('authenticate should populate header with base64 bearer', async () => {
// @ts-expect-error partial type
expect(ghcr.authenticate({}, { headers: {} })).resolves.toEqual({
await expect(ghcr.authenticate({}, { headers: {} })).resolves.toEqual({
headers: {
Authorization: 'Bearer dG9rZW4=',
},
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/unit-tests/modules/docker/Gitlab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('testing Gitlab Registry', () => {
).toBeTruthy();
});

test('authenticate should perform authenticate request', () => {
test('authenticate should perform authenticate request', async () => {
vi.mock('axios', () => {
const axios = vi.fn(() => {
return {
Expand All @@ -92,7 +92,7 @@ describe('testing Gitlab Registry', () => {
});
return { default: axios };
});
expect(
await expect(
gitlab.authenticate(
// @ts-expect-error partial type
{},
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/unit-tests/modules/docker/Hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ describe('testing Hub Registry', () => {
});
});

test('authenticate should perform authenticate request', () => {
expect(
test('authenticate should perform authenticate request', async () => {
await expect(
hub.authenticate(
// @ts-expect-error partial type
{},
Expand Down
4 changes: 2 additions & 2 deletions server/src/tests/unit-tests/modules/docker/Quay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ describe('testing Quay Registry', () => {
});
});

test('authenticate should populate header with base64 bearer', () => {
expect(quay.authenticate({}, { headers: {} })).resolves.toEqual({
test('authenticate should populate header with base64 bearer', async () => {
await expect(quay.authenticate({}, { headers: {} })).resolves.toEqual({
headers: {
Authorization: 'Bearer token',
},
Expand Down

0 comments on commit 7cc4954

Please sign in to comment.