Skip to content

Commit

Permalink
implemented basic nightwatch parser
Browse files Browse the repository at this point in the history
  • Loading branch information
DavertMik committed Feb 4, 2025
1 parent d4a88a0 commit 6aef174
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/lib/frameworks/nightwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const path = require('path');
module.exports = (ast, file = '', source = '') => {
let exported;

let beforeEach = '';
let beforeAll = '';

try {
exported = require(path.join(process.cwd(), file));
} catch (err) {
Expand All @@ -20,14 +23,31 @@ module.exports = (ast, file = '', source = '') => {

for (const testName in exported) {
if (typeof exported[testName] !== 'function') continue;
if (testName == 'beforeEach') {
beforeEach = exported[testName].toString();
continue;
}
if (testName == 'beforeAll') {
beforeAll = exported[testName].toString();
continue;
}

if (['beforeEach', 'afterEach', 'before', 'after'].includes(testName)) continue;

const testFn = exported[testName];

let code = testFn.toString();
if (beforeEach) {
code = `beforeEach(${beforeEach})\n\n${code}`;
}
if (beforeAll) {
code = `beforeAll(${beforeAll})\n\n${code}`;
}

tests.push({
name: testName,
suites: [file.split('/').pop()],
code: testFn.toString(),
code,
file,
});
}
Expand Down

0 comments on commit 6aef174

Please # to comment.