Created
June 26, 2018 05:47
-
-
Save Yuyz0112/a5b6bd357879143538b57b897c6485bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const argv = require('minimist')(process.argv.slice(2)); | |
const lodash = require('lodash'); | |
const setUrl = require('./utils/setUrl'); | |
const flattenArgs = args => { | |
let argsArr; | |
if (!args) { | |
argsArr = []; | |
} else if (lodash.isArray(args)) { | |
argsArr = args; | |
} else { | |
argsArr = [args]; | |
} | |
return argsArr.reduce((prev, cur) => prev.concat(cur.split(',')), []); | |
}; | |
// ..wizard/test/e2e/specs/user/operate_user_test.js -> user | |
const groupName = specFile => specFile.match(/.+\/(.*)\/.+\.js/)[1]; | |
const tag = flattenArgs(argv.tag); | |
const skiptags = flattenArgs(argv.skiptags); | |
const group = flattenArgs(argv.group); | |
const specFiles = []; | |
function traverseSpecFolder(parentPath) { | |
const paths = fs.readdirSync(parentPath); | |
paths.forEach(pathStr => { | |
const resolvedPathStr = path.resolve(parentPath, pathStr); | |
if (fs.lstatSync(resolvedPathStr).isDirectory()) { | |
traverseSpecFolder(resolvedPathStr); | |
} else if (path.extname(resolvedPathStr) === '.js') { | |
specFiles.push(resolvedPathStr); | |
} | |
}); | |
} | |
function transformSpecModule(specFile) { | |
let transformedModule = {}; | |
const module = require(specFile); | |
// check @disabled | |
if (module['@disabled']) { | |
return transformedModule; | |
} | |
// check @tags | |
if (tag.length && !lodash.intersection(tag, module['@tags']).length) { | |
return transformedModule; | |
} | |
if (skiptags.length && module['@tags'] && lodash.intersection(skiptags, module['@tags']).length) { | |
return transformedModule; | |
} | |
// check group | |
const moduleGroup = groupName(specFile); | |
if (group.length && !group.includes(moduleGroup)) { | |
return transformedModule; | |
} | |
const caseObj = lodash.omit(module, ['@disabled', '@tags', 'before', 'beforeEach']); | |
for (const caseName in caseObj) { | |
transformedModule[`${moduleGroup} - ${path.basename(specFile)} - ${caseName}`] = | |
caseObj[caseName]; | |
} | |
transformedModule.before = module.before; | |
transformedModule.beforeEach = module.beforeEach; | |
return transformedModule; | |
} | |
const suite = {}; | |
traverseSpecFolder(path.join(__dirname, 'specs')); | |
specFiles.forEach(specFile => lodash.merge(suite, transformSpecModule(specFile))); | |
suite.beforeEach = client => { | |
client.url(setUrl(client.launchUrl, { pathname: '/dashboard' })); | |
}; | |
suite.afterEach = (client, done) => { | |
client.execute( | |
function() { | |
window.localStorage.removeItem('CACHED_QUERY'); | |
}, | |
[], | |
result => { | |
done(); | |
} | |
); | |
}; | |
module.exports = suite; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment