Skip to content

Commit

Permalink
fix: fix jest timeout in cli cache tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mellyeliu committed Jan 29, 2025
1 parent 37fd779 commit 7902838
Showing 1 changed file with 56 additions and 45 deletions.
101 changes: 56 additions & 45 deletions packages/cli/__tests__/compile-stylex-folder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,30 +126,38 @@ describe('cli works with -i and -o args', () => {

test('script start', (done) => {
const onClose = async () => {
for (const dir of config.output) {
const outputDir = await fs.readdir(dir);
for (const file of outputDir) {
const snapshotDir = path.resolve(path.join(snapshot, file));
expect(
await fs
.access(snapshotDir)
.then(() => true)
.catch(() => false),
).toBe(true);
const outputPath = path.join(dir, file);
if (path.extname(outputPath) === '.js') {
const outputContent = await fs.readFile(outputPath, 'utf-8');
const snapshotContent = await fs.readFile(snapshotDir, 'utf-8');
expect(outputContent).toEqual(snapshotContent);
}
}
try {
await Promise.all(config.output.map(async (dir) => {
const outputDir = await fs.readdir(dir);
await Promise.all(outputDir.map(async (file) => {
const snapshotDir = path.resolve(snapshot, file);

const snapshotExists = await fs.access(snapshotDir).then(() => true).catch(() => false);
expect(snapshotExists).toBe(true);

const outputPath = path.join(dir, file);
if (path.extname(outputPath) === '.js') {
const [outputContent, snapshotContent] = await Promise.all([
fs.readFile(outputPath, 'utf-8'),
fs.readFile(snapshotDir, 'utf-8'),
]);
expect(outputContent).toEqual(snapshotContent);
}
}));
}));
} catch (err) {
done(err);
} finally {
await clearTestDir(config);
done();
}
await clearTestDir(config);
done();
};

runCli(`-i ${config.input[0]} -o ${config.output[0]}`, config, onClose);
}, 10000);
runCli(`-i ${config.input[0]} -o ${config.output[0]}`, config, () => {
onClose();
});
}, 20000);


test('script runs with absolute input and output paths', (done) => {
const absConfig: CliConfig = {
Expand Down Expand Up @@ -189,34 +197,37 @@ describe('cli works with multiple inputs and outputs', () => {

test('script compiles multiple directories', (done) => {
const onClose = async () => {
let isSecondOutput = false;
for (const dir of config.output) {
if (dir.endsWith('src2')) {
isSecondOutput = true;
}
const outputDir = await fs.readdir(dir);
for (const file of outputDir) {
if (isSecondOutput) {
expect(file).not.toContain(config.styleXBundleName);
try {
let isSecondOutput = false;
for (const dir of config.output) {
if (dir.endsWith('src2')) {
isSecondOutput = true;
}
const outputPath = path.join(dir, file);
const snapshotDir = isSecondOutput ? snapshot + '2' : snapshot;
const snapshotPath = path.join(snapshotDir, file);
expect(
await fs
.access(snapshotPath)
.then(() => true)
.catch(() => false),
).toBe(true);
if (path.extname(outputPath) === '.js') {
const outputContent = await fs.readFile(outputPath, 'utf-8');
const snapshotContent = await fs.readFile(snapshotPath, 'utf-8');
expect(outputContent).toEqual(snapshotContent);
const outputDir = await fs.readdir(dir);
for (const file of outputDir) {
if (isSecondOutput) {
expect(file).not.toContain(config.styleXBundleName);
}
const outputPath = path.join(dir, file);
const snapshotDir = isSecondOutput ? snapshot + '2' : snapshot;
const snapshotPath = path.join(snapshotDir, file);

const exists = await fs.access(snapshotPath).then(() => true).catch(() => false);
expect(exists).toBe(true);

if (path.extname(outputPath) === '.js') {
const outputContent = await fs.readFile(outputPath, 'utf-8');
const snapshotContent = await fs.readFile(snapshotPath, 'utf-8');
expect(outputContent).toEqual(snapshotContent);
}
}
}
} catch (err) {
console.error("Error in onClose:", err);

Check failure on line 226 in packages/cli/__tests__/compile-stylex-folder-test.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
} finally {
await clearTestDir(config);
done();
}
await clearTestDir(config);
done();
};
const input = config.input.join(' ');
const output = config.output.join(' ');
Expand Down

0 comments on commit 7902838

Please sign in to comment.