Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
"debug": "^4.3.4",
"lodash": "^4.17.21",
"pony-cause": "^2.1.10",
"semver": "^7.5.4",
"uuid": "^9.0.1"
"semver": "^7.5.4"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^3.0.4",
Expand All @@ -86,7 +85,6 @@
"@types/jest": "^28.1.7",
"@types/jest-when": "^3.5.3",
"@types/node": "~18.18.14",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"depcheck": "^1.4.7",
Expand Down
16 changes: 8 additions & 8 deletions src/fs.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import crypto from 'crypto';
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
import fs from 'fs';
import { when } from 'jest-when';
import os from 'os';
import path from 'path';
import util from 'util';
import * as uuid from 'uuid';

import {
createSandbox,
Expand All @@ -19,13 +19,13 @@ import {

const { withinSandbox } = createSandbox('utils');

// Clone the `uuid` module so that we can spy on its exports
jest.mock('uuid', () => {
// Clone the `crypto` module so that we can spy on its exports
jest.mock('crypto', () => {
return {
// This is how to mock an ES-compatible module in Jest.
// eslint-disable-next-line @typescript-eslint/naming-convention
__esModule: true,
...jest.requireActual('uuid'),
...jest.requireActual('crypto'),
};
});

Expand Down Expand Up @@ -685,7 +685,7 @@ describe('fs', () => {
});

it('does not create the sandbox directory immediately', async () => {
jest.spyOn(uuid, 'v4').mockReturnValue('AAAA-AAAA-AAAA-AAAA');
jest.spyOn(crypto, 'randomUUID').mockReturnValue('AAAA-AAAA-AAAA-AAAA');
createSandbox('utils-fs');

const sandboxDirectoryPath = path.join(
Expand All @@ -702,7 +702,7 @@ describe('fs', () => {
describe('withinSandbox', () => {
it('creates the sandbox directory and keeps it around before its given function ends', async () => {
expect.assertions(1);
jest.spyOn(uuid, 'v4').mockReturnValue('AAAA-AAAA-AAAA-AAAA');
jest.spyOn(crypto, 'randomUUID').mockReturnValue('AAAA-AAAA-AAAA-AAAA');
const { withinSandbox: withinTestSandbox } = createSandbox('utils-fs');

await withinTestSandbox(async () => {
Expand All @@ -718,7 +718,7 @@ describe('fs', () => {
});

it('removes the sandbox directory after its given function ends', async () => {
jest.spyOn(uuid, 'v4').mockReturnValue('AAAA-AAAA-AAAA-AAAA');
jest.spyOn(crypto, 'randomUUID').mockReturnValue('AAAA-AAAA-AAAA-AAAA');
const { withinSandbox: withinTestSandbox } = createSandbox('utils-fs');

await withinTestSandbox(async () => {
Expand All @@ -736,7 +736,7 @@ describe('fs', () => {
});

it('throws if the sandbox directory already exists', async () => {
jest.spyOn(uuid, 'v4').mockReturnValue('AAAA-AAAA-AAAA-AAAA');
jest.spyOn(crypto, 'randomUUID').mockReturnValue('AAAA-AAAA-AAAA-AAAA');
const { withinSandbox: withinTestSandbox } = createSandbox('utils-fs');

const sandboxDirectoryPath = path.join(
Expand Down
4 changes: 2 additions & 2 deletions src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as uuid from 'uuid';
import * as crypto from 'crypto';

import { isErrorWithCode, wrapError } from './errors';
import type { Json } from './json';
Expand Down Expand Up @@ -241,7 +241,7 @@ export async function forceRemove(entryPath: string): Promise<void> {
* ```
*/
export function createSandbox(projectName: string): FileSandbox {
const directoryPath = path.join(os.tmpdir(), projectName, uuid.v4());
const directoryPath = path.join(os.tmpdir(), projectName, crypto.randomUUID());

return {
directoryPath,
Expand Down