Skip to content

Commit 5e2a24a

Browse files
committedJun 11, 2021
wait for json file
1 parent e26471e commit 5e2a24a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
 

‎__tests__/all-defaults-with-json/transform.test.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from "path";
2-
import { promises as fsAsync } from "fs";
2+
import fs, { promises as fsAsync } from "fs";
33
import prettier from "prettier";
44
import * as assert from "assert";
55
import postcss from "postcss";
@@ -18,6 +18,15 @@ const plugins = [
1818
}),
1919
];
2020

21+
const waitForFile = (path: string) =>
22+
new Promise<void>(async (resolve) => {
23+
while (!fs.existsSync(path)) {
24+
await new Promise((a) => setTimeout(a, 50));
25+
}
26+
await new Promise((a) => setTimeout(a, 0));
27+
resolve();
28+
});
29+
2130
describe("Default with json", () => {
2231
it("should transform css and module json", async () => {
2332
/** Path to the input css file */
@@ -64,6 +73,8 @@ describe("Default with json", () => {
6473
})
6574
);
6675

76+
await waitForFile(path.join(__dirname, "./dist/modules.json"));
77+
6778
const generateJSON = JSON.parse(
6879
await fsAsync.readFile(
6980
path.join(__dirname, "./dist/modules.json"),

0 commit comments

Comments
 (0)
Please sign in to comment.