Skip to content
Closed

vitest2 #6582

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"vitest.disableWorkspaceWarning": true
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"fs-extra": "^9.0.0",
"generate-changelog": "^1.7.1",
"glob": "7.1.6",
"happy-dom": "14.12.3",
"husky": "^4.2.3",
"jasmine-core": "^3.5.0",
"jest": "29.7.0",
Expand Down Expand Up @@ -121,6 +122,7 @@
"turbo": "2.1.2",
"typescript": "~4.9.5",
"verdaccio": "5.25.0",
"vitest": "0.34.6",
"webpack": "5.76.0",
"webpack-cli": "4.10.0",
"yargs": "17.5.1",
Expand Down
6 changes: 0 additions & 6 deletions packages/body-checksum-browser/jest.config.js

This file was deleted.

3 changes: 2 additions & 1 deletion packages/body-checksum-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "jest"
"test": "vitest run"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand All @@ -34,6 +34,7 @@
"@tsconfig/recommended": "1.0.1",
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
"happy-dom": "^15.7.4",
"rimraf": "3.0.2",
"typescript": "~4.9.5"
},
Expand Down
5 changes: 4 additions & 1 deletion packages/body-checksum-browser/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Sha256 } from "@aws-crypto/sha256-js";
import { HttpRequest } from "@smithy/protocol-http";
import { fromUtf8 } from "@smithy/util-utf8";
import { Readable } from "stream";
import { describe, expect, test as it } from "vitest";

import { bodyChecksumGenerator } from ".";

Expand Down Expand Up @@ -54,7 +55,9 @@ describe("bodyChecksumGenerator for browser", () => {
try {
await bodyChecksumGenerator(request, options);
} catch (e) {
expect(e).toEqual(new Error("Unable to calculate checksums for non-blob streams."));
expect(e).toEqual(
new Error("Unable to calculate checksums for non-blob streams, received: Readable:[object Object].")
);
}
});
});
11 changes: 9 additions & 2 deletions packages/body-checksum-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export async function bodyChecksumGenerator(
contentHash.update(toUint8Array(body));
treeHash.update(body);
} else {
if (Boolean(body) && Object.prototype.toString.call(body) === "[object Blob]") {
if (
Boolean(body) &&
(Object.prototype.toString.call(body) === "[object Blob]" || body.constructor?.name === "Blob")
) {
await blobReader(
body,
(chunk: any) => {
Expand All @@ -33,7 +36,11 @@ export async function bodyChecksumGenerator(
MiB
);
} else {
throw new Error("Unable to calculate checksums for non-blob streams.");
throw new Error(
`Unable to calculate checksums for non-blob streams, received: ${
body.constructor.name + ":" + Object.prototype.toString.call(body)
}.`
);
}
}

Expand Down
9 changes: 9 additions & 0 deletions packages/body-checksum-browser/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: ["**/*.{integ,e2e}.spec.{ts,js}"],
include: ["**/*.spec.{ts,js}"],
environment: "happy-dom",
},
});
5 changes: 0 additions & 5 deletions packages/body-checksum-node/jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/body-checksum-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "jest"
"test": "vitest run"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/body-checksum-node/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createReadStream, mkdtempSync, writeFileSync } from "fs";
import { tmpdir } from "os";
import { join } from "path";
import { Readable } from "stream";
import { describe, expect, test as it } from "vitest";

import { bodyChecksumGenerator } from ".";

Expand Down
9 changes: 9 additions & 0 deletions packages/body-checksum-node/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: ["**/*.{integ,e2e,browser}.spec.{ts,js}"],
include: ["**/*.spec.{ts,js}"],
environment: "node",
},
});
5 changes: 0 additions & 5 deletions packages/chunked-stream-reader-node/jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/chunked-stream-reader-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "jest"
"test": "vitest run"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
15 changes: 8 additions & 7 deletions packages/chunked-stream-reader-node/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PassThrough } from "stream";
import { describe, expect, test as it, vi } from "vitest";

import { streamReader } from "./index";
import { ReadFromBuffers } from "./readable.fixture";
Expand All @@ -8,7 +9,7 @@ describe("streamReader", () => {
const buffers = [Buffer.alloc(1024, 0), Buffer.alloc(1024, 1), Buffer.alloc(1024, 2), Buffer.alloc(1024, 3)];
const mockStream = new ReadFromBuffers({ buffers });

const mockChunkReader = jest.fn();
const mockChunkReader = vi.fn();

await streamReader(mockStream, mockChunkReader, 1024);
const mockChunkCalls = mockChunkReader.mock.calls;
Expand All @@ -28,7 +29,7 @@ describe("streamReader", () => {
];
const mockStream = new ReadFromBuffers({ buffers });

const mockChunkReader = jest.fn();
const mockChunkReader = vi.fn();

await streamReader(mockStream, mockChunkReader);
const mockChunkCalls = mockChunkReader.mock.calls;
Expand All @@ -43,7 +44,7 @@ describe("streamReader", () => {
const buffers = [Buffer.alloc(1000, 0), Buffer.alloc(1000, 1), Buffer.alloc(1000, 2), Buffer.alloc(600, 3)];
const mockStream = new ReadFromBuffers({ buffers });

const mockChunkReader = jest.fn();
const mockChunkReader = vi.fn();

await streamReader(mockStream, mockChunkReader, 500);

Expand All @@ -69,7 +70,7 @@ describe("streamReader", () => {
];
const mockStream = new ReadFromBuffers({ buffers });

const mockChunkReader = jest.fn();
const mockChunkReader = vi.fn();

await streamReader(mockStream, mockChunkReader, 500);

Expand All @@ -83,7 +84,7 @@ describe("streamReader", () => {
const buffers = [Buffer.alloc(100, 0), Buffer.alloc(100, 1), Buffer.alloc(100, 2)];
const mockStream = new ReadFromBuffers({ buffers });

const mockChunkReader = jest.fn();
const mockChunkReader = vi.fn();

await streamReader(mockStream, mockChunkReader, 500);

Expand All @@ -98,7 +99,7 @@ describe("streamReader", () => {
const payload = Buffer.alloc(700, 0);
mockStream.end(payload);

const mockChunkReader = jest.fn();
const mockChunkReader = vi.fn();
await streamReader(mockStream, mockChunkReader, 500);

const mockChunkCalls = mockChunkReader.mock.calls;
Expand All @@ -123,7 +124,7 @@ describe("streamReader", () => {
errorAfter: 2, // throw error after 2 chunks have been read
});

const mockChunkReader = jest.fn();
const mockChunkReader = vi.fn();

await expect(streamReader(mockStream, mockChunkReader, 500)).rejects.toHaveProperty("message");
});
Expand Down
9 changes: 9 additions & 0 deletions packages/chunked-stream-reader-node/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: ["**/*.{integ,e2e,browser}.spec.{ts,js}"],
include: ["**/*.spec.{ts,js}"],
environment: "node",
},
});
6 changes: 0 additions & 6 deletions packages/cloudfront-signer/jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cloudfront-signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"test": "jest"
"test": "vitest run"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/cloudfront-signer/src/sign.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parseUrl } from "@smithy/url-parser";
import { createSign, createVerify } from "crypto";
import { describe, expect, test as it } from "vitest";

import { getSignedCookies, getSignedUrl } from "./index";

Expand Down
9 changes: 9 additions & 0 deletions packages/cloudfront-signer/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: ["**/*.{integ,e2e,browser}.spec.{ts,js}"],
include: ["**/*.spec.{ts,js}"],
environment: "node",
},
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { test as it, describe, expect } from "vitest";

import { Kinesis } from "@aws-sdk/client-kinesis";
import { S3 } from "@aws-sdk/client-s3";
import { TranscribeStreaming } from "@aws-sdk/client-transcribe-streaming";
Expand Down
4 changes: 0 additions & 4 deletions packages/core/jest.config.integ.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/core/jest.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"lint": "node ./scripts/lint.js",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"test": "jest",
"test:integration": "jest -c jest.config.integ.js"
"test": "vitest run",
"test:integration": "vitest run -c vitest.config.integ.ts"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test as it } from "vitest";

import { validateAccountIdEndpointMode } from "./AccountIdEndpointModeConstants";

describe("validateAccountIdEndpointMode", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";

import { DEFAULT_ACCOUNT_ID_ENDPOINT_MODE } from "./AccountIdEndpointModeConstants";
import {
CONFIG_ACCOUNT_ID_ENDPOINT_MODE,
Expand All @@ -9,7 +11,7 @@ describe("NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS", () => {
const originalEnv = process.env;

beforeEach(() => {
jest.resetModules();
vi.resetModules();
process.env = { ...originalEnv };
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";

import { emitWarningIfUnsupportedVersion, state } from "./emitWarningIfUnsupportedVersion";

describe("emitWarningIfUnsupportedVersion", () => {
let emitWarningIfUnsupportedVersion: any;
const emitWarning = process.emitWarning;
const supportedVersion = "18.0.0";

beforeEach(() => {
const module = require("./emitWarningIfUnsupportedVersion");
emitWarningIfUnsupportedVersion = module.emitWarningIfUnsupportedVersion;
});
beforeEach(() => {});

afterEach(() => {
jest.clearAllMocks();
jest.resetModules();
vi.clearAllMocks();
vi.resetModules();
process.emitWarning = emitWarning;
state.warningEmitted = false;
});

describe(`emits warning for Node.js <${supportedVersion}`, () => {
Expand All @@ -31,7 +32,7 @@ describe("emitWarningIfUnsupportedVersion", () => {
[getPreviousMajorVersion(major), 0, 0],
].map((arr) => `v${arr.join(".")}`)
)(`%s`, async (unsupportedVersion) => {
process.emitWarning = jest.fn();
process.emitWarning = vi.fn() as any;
emitWarningIfUnsupportedVersion(unsupportedVersion);

// Verify that the warning was emitted.
Expand Down Expand Up @@ -62,7 +63,7 @@ More information can be found at: https://a.co/74kJMmI`
[major + 1, 0, 0],
].map((arr) => `v${arr.join(".")}`)
)(`%s`, async (unsupportedVersion) => {
process.emitWarning = jest.fn();
process.emitWarning = vi.fn() as any;
emitWarningIfUnsupportedVersion(unsupportedVersion);
expect(process.emitWarning).not.toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Stores whether the warning was already emitted.
let warningEmitted = false;
export const state = {
warningEmitted: false,
};

/**
* @internal
Expand All @@ -10,8 +12,8 @@ let warningEmitted = false;
* @param version - The Node.js version string.
*/
export const emitWarningIfUnsupportedVersion = (version: string) => {
if (version && !warningEmitted && parseInt(version.substring(1, version.indexOf("."))) < 18) {
warningEmitted = true;
if (version && !state.warningEmitted && parseInt(version.substring(1, version.indexOf("."))) < 18) {
state.warningEmitted = true;
process.emitWarning(
`NodeDeprecationWarning: The AWS SDK for JavaScript (v3) will
no longer support Node.js 16.x on January 6, 2025.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AttributedAwsCredentialIdentity } from "@aws-sdk/types";
import { describe, expect, test as it } from "vitest";

import { setCredentialFeature } from "./setCredentialFeature";

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/submodules/client/setFeature.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AwsHandlerExecutionContext } from "@aws-sdk/types";
import { describe, test as it } from "vitest";

import { setFeature } from "./setFeature";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test as it } from "vitest";

import { AwsSdkSigV4Signer } from "./AwsSdkSigV4Signer";

describe(AwsSdkSigV4Signer.name, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test as it } from "vitest";

import { resolveAwsSdkSigV4AConfig } from "./resolveAwsSdkSigV4AConfig";

describe(resolveAwsSdkSigV4AConfig.name, () => {
Expand Down
Loading
Loading