1

I have the following function

const extractTestCases = () => {
    const filterFile = files.filter(test => test.includes('.test.ts'))
    filterFile.forEach(testsuite => {
        const testSuites = fs.readFileSync(testsuite, { encoding: "utf8" });
        testCases.push(regexMatcher(testSuites, TestRegex, 1))
    })
    return testCases;
}

filterFile is an array for multiple files where I'm making forEach loop to extract some information from each file, what I want to do is to return an array of objects like this

[{"name of the file (testSuite)":["extracted value from this file regexMatcher(testSuites, TestRegex, 1)"]},{"testSuite2":["","",""]},...]

1 Answer 1

2

Try something like this :

const extractTestCases = () => {
        const filesArray = []
        const filterFile = files.filter(test => test.includes('.test.ts'))
        filterFile.forEach(testsuite => {
            const testSuites = fs.readFileSync(testsuite, { encoding: "utf8" });
            testCases.push(regexMatcher(testSuites, TestRegex, 1))
            filesArray.push({[testsuite]: regexMatcher(testSuites, TestRegex, 1)})
        })
        return filesArray;
    } 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.