Home > database >  testcafe - Source files do not contain valid 'fixture' and 'test' declarations
testcafe - Source files do not contain valid 'fixture' and 'test' declarations

Time:09-17

I'm writing a test in testcafe for the first time, and trying to do a forEach loop in order to iterate various files. When trying to run the test, getting this error Source files do not contain valid 'fixture' and 'test' declarations.

import testcafe from 'testcafe';
import { promises } from 'fs';
import { parse } from 'node-html-parser';

let specFiles: string[] = [];

fixture ('OpsLevel test cafe reporter').before( async t => {
    specFiles = await promises.readdir('./gauge-reports/html-report/specs')    
});

specFiles.forEach(specFile => {
    test(`Generate testcafe report from ${specFile}`, async t => {
        const gaugeReport = await promises.readFile(specFile, {encoding: 'utf8', flag: 'r'});
        const parsedReport = parse(gaugeReport);
        const structuredText = parsedReport.structuredText;
    
        await t.expect(structuredText.includes('Success Rate 100%')).eql(true);
    });
});

Please advise.

CodePudding user response:

Runtime DataSet initialization for data driven tests is not supported. Please refer to the documentation to learn how to properly initialize a dataset.

  • Related