Using Playwright, I have this dummy test:
import { test, expect, chromium } from '@playwright/test';
import * as path from "path";
import fs from "fs-extra";
const INPUT_DIR = path.resolve(__dirname, "./../data");
const items1 = JSON.stringify((await fs.readJson(path.resolve(INPUT_DIR, "items1.json"))));
const expected1 = '0.999999111111';
test("test1", async () => {
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('http://localhost:3000');
expect('abc').toContain('a'); // <-- dummy test
});
I run the test with:
npx playwright test readJsonAsyncProblem.spec.ts
I get (exact and full output):
SyntaxError: missing ) after argument list
Error: No tests found
I've faced the same problem using "await csvtojson" in other playwright tests.
If I change line #5 to:
const items1 = JSON.stringify((fs.readJsonSync(path.resolve(INPUT_DIR, "items1.json"))));
the test passes.
I could not figure out why using await readJson causes this problem. My experience is limited in Playwright. Help is appreciated.