Skip to content

Commit d49a5b7

Browse files
committed
Added vitest testutils module
1 parent ab5caa3 commit d49a5b7

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default defineConfig({
3333
alias: {
3434
"@src": path.resolve(__dirname, "src"),
3535
"@types": path.resolve(__dirname, "types/internal.d.ts"),
36-
"@testutils": path.resolve(__dirname, "testutils"),
36+
"@testutils": path.resolve(__dirname, "vitest/testutils/index.ts"),
3737
},
3838
},
3939
});

vitest/tests/utils.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
* SPDX-License-Identifier: Apache-2.0
1010
*/
1111

12-
import crypto from "node:crypto";
1312
import fs from "node:fs";
14-
import { tmpdir } from "node:os";
1513
import path from "node:path";
1614
import utils from "@src/utils";
15+
import * as tu from "@testutils";
1716
import type * as t from "@types";
1817
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
1918

2019
describe("searchUpwards", () => {
21-
const tempBase = path.join(tmpdir(), "vitest", crypto.randomBytes(8).toString("hex"));
20+
const tempBase = tu.getTempDirPath();
2221
const subDirName = "sub-dir";
2322
const nestedSubDirName = "nested-sub-dir";
2423
const targetFileName = "targetFile.txt";

vitest/tests/worker.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
* SPDX-License-Identifier: Apache-2.0
1010
*/
1111

12-
import crypto from "node:crypto";
1312
import fsp from "node:fs/promises";
14-
import { tmpdir } from "node:os";
1513
import path from "node:path";
1614
import { Worker } from "node:worker_threads";
1715
import * as c from "@src/constants";
1816
import * as s from "@src/schemas";
1917
import utils from "@src/utils";
18+
import * as tu from "@testutils";
2019
import type * as t from "@types";
2120
import { assert } from "superstruct";
2221
import { describe, expect, it } from "vitest";
@@ -26,7 +25,7 @@ describe("worker", () => {
2625
it("should use worker threads to download and decompress archives", options, async () => {
2726
const option: t.RemoteBlobOption = {
2827
url: "https://github.com/aabmets/rollup-plugin-pull-remote-blob/archive/refs/heads/main.zip",
29-
dest: path.join(tmpdir(), "vitest", crypto.randomBytes(8).toString("hex")),
28+
dest: tu.getTempDirPath(),
3029
decompress: {
3130
filter: ["README.md", "src"],
3231
strip: 1,

vitest/testutils/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2024, Mattias Aabmets
5+
*
6+
* The contents of this file are subject to the terms and conditions defined in the License.
7+
* You may not use, modify, or distribute this file except in compliance with the License.
8+
*
9+
* SPDX-License-Identifier: Apache-2.0
10+
*/
11+
12+
import crypto from "node:crypto";
13+
import { tmpdir } from "node:os";
14+
import path from "node:path";
15+
16+
export function getTempDirPath() {
17+
const randString = crypto.randomBytes(8).toString("hex");
18+
return path.join(tmpdir(), "vitest", randString);
19+
}

0 commit comments

Comments
 (0)