Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fail to test specific package #2099

Merged
merged 3 commits into from Mar 10, 2020
Merged

fix: fail to test specific package #2099

merged 3 commits into from Mar 10, 2020

Conversation

billyyyyy3320
Copy link
Collaborator

@billyyyyy3320 billyyyyy3320 commented Dec 30, 2019

Summary

yarn test will run every tests in all workspaces.

When I looked at the source code, I found that there's an option to test a specific package:

// scripts/test.js
if (args.p) {
  const packages = (args.p || args.package).split(',').join('|')
  regex = `.*@vuepress/(${packages}|plugin-(${packages}))/.*\\.spec\\.(js|ts)$`
  const i = rawArgs.indexOf('-p')
  rawArgs.splice(i, 2)
}

const jestRunner = createJestRunner([
  '--config', 'scripts/jest.config.js',
  '--runInBand',
  ...(regex ? [regex] : [])
], rawArgs)

But when I ran yarn test -p core, it failed with ReferenceError: core is not defined.

I tracked down createJestRunner and found it is caused by #1404.

The rawArgs is supposed to contain '--inspect-brk', but it will also contain'-p' and 'core' if I run yarn test --inspect-brk -p core :

// @test-utils/lib/createJestRunner.js
const execa = require('execa')
const rawArgs = process.argv.slice(2)

const usedPorts = []

module.exports = function createJestRunner (jestArgs) {
  return async function () {
    const execArgv = getChildProcesExecArgv()
    const args = [...execArgv, ...jestArgs]
    console.log(`running node with args: ${args.join(' ')}`)
    args.unshift(...rawArgs, require.resolve('jest-cli/bin/jest'))
    await execa('node', args, {
      stdio: 'inherit'
    })
  }
}

Since rawArgs has been processed properly in scripts/test.js:

  const i = rawArgs.indexOf('-p')
  rawArgs.splice(i, 2)

I add a argument - rawArgs to createJestRunner. It also make it a bit more reusable.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

If changing the UI of default theme, please provide the before/after screenshot:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome
  • Firefox
  • Safari
  • Edge
  • IE

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

@@ -8,7 +8,7 @@ const args = minimist(rawArgs)
let regex
if (args.p) {
const packages = (args.p || args.package).split(',').join('|')
regex = `.*@vuepress/(${packages}|plugin-(${packages}))/.*\\.spec\\.js$`
regex = `.*@vuepress/(${packages}|plugin-(${packages}))/.*\\.spec\\.(js|ts)$`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit because tests in shared-utils are .ts files.

@billyyyyy3320
Copy link
Collaborator Author

Later, I think the second arg of createJestRunner - rawArgs is kinda weird since it can only contain --inspect-brk. I change it into accepting a simple boolean: 6547f8e

@billyyyyy3320 billyyyyy3320 merged commit 0aadf05 into master Mar 10, 2020
@billyyyyy3320 billyyyyy3320 deleted the fix/test branch March 10, 2020 12:42
larionov pushed a commit to larionov/vuepress that referenced this pull request Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants