Skip to content

Commit 3c32a47

Browse files
committed
test: convert 4 packages to vitest
1 parent 81fea7c commit 3c32a47

File tree

20 files changed

+82
-38
lines changed

20 files changed

+82
-38
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"fs-extra": "^9.0.0",
9393
"generate-changelog": "^1.7.1",
9494
"glob": "7.1.6",
95+
"happy-dom": "^15.7.4",
9596
"husky": "^4.2.3",
9697
"jasmine-core": "^3.5.0",
9798
"jest": "29.7.0",

packages/body-checksum-browser/jest.config.js

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

packages/body-checksum-browser/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build:types": "tsc -p tsconfig.types.json",
1010
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12-
"test": "jest"
12+
"test": "vitest run"
1313
},
1414
"main": "./dist-cjs/index.js",
1515
"module": "./dist-es/index.js",
@@ -34,6 +34,7 @@
3434
"@tsconfig/recommended": "1.0.1",
3535
"concurrently": "7.0.0",
3636
"downlevel-dts": "0.10.1",
37+
"happy-dom": "^15.7.4",
3738
"rimraf": "3.0.2",
3839
"typescript": "~4.9.5"
3940
},

packages/body-checksum-browser/src/index.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Sha256 } from "@aws-crypto/sha256-js";
22
import { HttpRequest } from "@smithy/protocol-http";
33
import { fromUtf8 } from "@smithy/util-utf8";
44
import { Readable } from "stream";
5+
import { describe, expect, test as it } from "vitest";
56

67
import { bodyChecksumGenerator } from ".";
78

@@ -54,7 +55,9 @@ describe("bodyChecksumGenerator for browser", () => {
5455
try {
5556
await bodyChecksumGenerator(request, options);
5657
} catch (e) {
57-
expect(e).toEqual(new Error("Unable to calculate checksums for non-blob streams."));
58+
expect(e).toEqual(
59+
new Error("Unable to calculate checksums for non-blob streams, received: Readable:[object Object].")
60+
);
5861
}
5962
});
6063
});

packages/body-checksum-browser/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export async function bodyChecksumGenerator(
2323
contentHash.update(toUint8Array(body));
2424
treeHash.update(body);
2525
} else {
26-
if (Boolean(body) && Object.prototype.toString.call(body) === "[object Blob]") {
26+
if (
27+
Boolean(body) &&
28+
(Object.prototype.toString.call(body) === "[object Blob]" || body.constructor?.name === "Blob")
29+
) {
2730
await blobReader(
2831
body,
2932
(chunk: any) => {
@@ -33,7 +36,11 @@ export async function bodyChecksumGenerator(
3336
MiB
3437
);
3538
} else {
36-
throw new Error("Unable to calculate checksums for non-blob streams.");
39+
throw new Error(
40+
`Unable to calculate checksums for non-blob streams, received: ${
41+
body.constructor.name + ":" + Object.prototype.toString.call(body)
42+
}.`
43+
);
3744
}
3845
}
3946

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: ["**/*.{integ,e2e}.spec.{ts,js}"],
6+
include: ["**/*.spec.{ts,js}"],
7+
environment: "happy-dom",
8+
},
9+
});

packages/body-checksum-node/jest.config.js

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

packages/body-checksum-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build:types": "tsc -p tsconfig.types.json",
1010
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12-
"test": "jest"
12+
"test": "vitest run"
1313
},
1414
"main": "./dist-cjs/index.js",
1515
"module": "./dist-es/index.js",

packages/body-checksum-node/src/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createReadStream, mkdtempSync, writeFileSync } from "fs";
55
import { tmpdir } from "os";
66
import { join } from "path";
77
import { Readable } from "stream";
8+
import { describe, expect, test as it } from "vitest";
89

910
import { bodyChecksumGenerator } from ".";
1011

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: ["**/*.{integ,e2e,browser}.spec.{ts,js}"],
6+
include: ["**/*.spec.{ts,js}"],
7+
environment: "node",
8+
},
9+
});

0 commit comments

Comments
 (0)