Skip to content

Commit

Permalink
Update jest-fast-check.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz authored Oct 27, 2024
1 parent f893f50 commit e693c59
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/jest/test/jest-fast-check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,15 @@ async function writeToFile(
fileContent: () => void,
): Promise<{ specFileName: string; jestConfigRelativePath: string }> {
const { useWorkers } = options;
const specFileSeed = Math.random().toString(16).substring(2);

// Prepare directory for spec
const specDirectorySeed = `${Math.random().toString(16).substring(2)}-${++num}`;
const specDirectory = path.join(generatedTestsDirectory, `test-${specDirectorySeed}`);
await fs.mkdir(specDirectory, { recursive: true });

// Prepare test file itself
const specFileName = `generated-${specFileSeed}-${++num}.spec.cjs`;
const specFilePath = path.join(generatedTestsDirectory, specFileName);
const specFileName = `generated.spec.cjs`;
const specFilePath = path.join(specDirectory, specFileName);
let fileContentString = String(fileContent);
if (fileContentString.includes('expect')) {
// "expect" would be replaced by Vitest by "__vite_ssr_import_0__.expect"
Expand All @@ -600,9 +604,8 @@ async function writeToFile(
);

// Prepare jest config itself
const jestConfigName = `jest.config-${specFileSeed}.cjs`;
const jestConfigRelativePath = `${generatedTestsDirectoryName}/${jestConfigName}`;
const jestConfigPath = path.join(generatedTestsDirectory, jestConfigName);
const jestConfigName = `jest.config.cjs`;
const jestConfigPath = path.join(specDirectory, jestConfigName);

// Write the files
await Promise.all([
Expand All @@ -615,11 +618,12 @@ async function writeToFile(
),
]);

return { specFileName, jestConfigRelativePath };
return { specDirectory, specFileName, jestConfigName };
}

async function runSpec(
jestConfigRelativePath: string,
specDirectory: string,
jestConfigName: string,
opts: { jestSeed?: number; testTimeoutCLI?: number } = {},
): Promise<string> {
const { stdout: jestBinaryPathCommand } = await execFile('yarn', ['bin', 'jest'], { shell: true });
Expand Down

0 comments on commit e693c59

Please sign in to comment.