Skip to content

Commit

Permalink
fix: 适配workspaces的方式跑单测和e2e测试
Browse files Browse the repository at this point in the history
  • Loading branch information
倪俊杰 committed Mar 29, 2022
1 parent 6276043 commit c09f85c
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions packages/epay-sparta-service/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class Service {
process.env.NODE_ENV = 'test'
process.env.BABEL_ENV = 'test'
defaultWebpackConfig = require('./webpack/webpack.config.test').getConfig(this)
SubService = this.resolveNpmPackage('@epay-sparta/cli-plugin-unit-test')
SubService = require('@epay-sparta/cli-plugin-unit-test')
break
case 'test:e2e':
SubService = this.resolveNpmPackage('@epay-sparta/cli-plugin-e2e-test')
SubService = require('@epay-sparta/cli-plugin-e2e-test')
break
// If mode is not the one of values unpon, show error tip.
default:
Expand All @@ -56,23 +56,6 @@ class Service {
return path.resolve(process.cwd(), dir)
}

resolveNpmPackage(packageName) {
const pkgJson = require(this.resolve('package.json'))
const hasTargetPackageInPkgJson =
pkgJson.devDependencies.hasOwnProperty(packageName) ||
pkgJson.dependencies.hasOwnProperty(packageName)
if (hasTargetPackageInPkgJson) {
const targetPkgPath = this.resolve(`node_modules/${packageName}`)
const targetPkgJson = this.require(`${targetPkgPath}/package.json`)
return require(path.resolve(targetPkgPath, targetPkgJson.main))
}
error(
`The npm package '${packageName}' hasn't be installed.\n` +
`You may try: npm install -S ${packageName}.`
)
process.exit(1)
}

require(path) {
return fs.existsSync(path) ? require(path) : {}
}
Expand Down

0 comments on commit c09f85c

Please sign in to comment.