Skip to content

Instantly share code, notes, and snippets.

@Meir017
Created June 2, 2020 04:50
Show Gist options
  • Save Meir017/e37474d82c17a49b545c90c89e5b1b4d to your computer and use it in GitHub Desktop.
Save Meir017/e37474d82c17a49b545c90c89e5b1b4d to your computer and use it in GitHub Desktop.
generate-tests-list
const utils = require('./test/utils');
const tests = require('./test/playwright.spec');
const collected = [];
let current = {};
var options = {
playwrightPath: utils.projectRoot(),
product: 'Firefox',
playwright: require('.'),
expect: () => { },
testRunner: {
describe: (name, func) => {
if (current.name) {
collected.push(current);
current = {};
}
current.name = name;
current.it = [];
func(options);
},
xdescribe: (name, func) => options.testRunner.describe(name, func),
fdescribe: (name, func) => options.testRunner.describe(name, func),
beforeEach: func => { },
beforeAll: func => { },
afterEach: func => { },
afterAll: func => { },
it: (name, func) => {
current.it.push({
name,
// code: func.toString()
});
},
xit: (name, func) => {
current.it.push({
name,
// code: func.toString(),
skip: true
});
},
loadTests: (module, ...args) => {
if (typeof module.describe === 'function')
options.testRunner.describe('', module.describe);
if (typeof module.fdescribe === 'function')
options.testRunner.fdescribe('', module.fdescribe);
if (typeof module.xdescribe === 'function')
options.testRunner.xdescribe('', module.xdescribe);
}
}
};
options.testRunner.it.skip = (skip) => (name, func) => options.testRunner.xit(name, func);
options.testRunner.describe.skip = (skip) => (name, func) => options.testRunner.describe(name, func);
tests.describe(options);
const fs = require('fs');
fs.writeFileSync('./test.json', JSON.stringify(collected, null, 2));
@Meir017
Copy link
Author

Meir017 commented Jun 2, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment