0

I am trying to adapt my npm run test and npm run test-watch scripts so that I have 2 - one that runs a subset of tests and one that runs the majority, as I have some slow run tests I don't want running with the main set.

I tried just adding a pattern like this:

  "scripts": {
    "test": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" vue-cli-service test:unit *.spec.js",
    "test-long": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" vue-cli-service test:unit *-long.spec.js"
  }

But get the error:

Invalid testPattern *-long.spec.js supplied. Running all tests instead.

I have now tried applying some RegEx escapes to the string, looking at other examples on various sites, but it still tells me that the pattern is invalid...

"test-long": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" vue-cli-service test:unit (*-long\\.spec\\.js$)"

Invalid testPattern (*-long\.spec\.js$) supplied. Running all tests instead.

Keith Jackson
  • 3,078
  • 4
  • 38
  • 66
  • `vue-cli-service test:unit` takes whatever command line flags Jest takes (see https://jestjs.io/docs/en/cli), no? See e.g. https://stackoverflow.com/q/42827054/3001761 for specifying tests to run. Your usage of `transformIgnorePatterns` doesn't make sense, that syntax is for the config file not the CLI. – jonrsharpe May 20 '20 at 11:08
  • I have already read the linked article through in detail, it got me this far - I don't want to run a single test - I want the script to run a group of tests but I keep getting the errors as above. My usage of `transformIgnorePatterns` has never been a problem before and has been in place for a long time - it is specific to the test commands. If it's wrong I'm not sure how it should be. – Keith Jackson May 20 '20 at 11:19
  • As the [Vue CLI](https://cli.vuejs.org/core-plugins/unit-jest.html#configuration) and [Jest](https://jestjs.io/docs/en/configuration) docs say it should be in `jest.config.js` or `package.json`. It's not the right format for CLI arguments, which would be e.g. `--transformIgnorePatterns=...` if supported. The message tells you your `testPattern` is invalid, so clearly it's going to the right place and once you remove that it should work as expected. – jonrsharpe May 20 '20 at 11:23
  • I've just tried that and I still get the same problem (different error of course) - will add to above... – Keith Jackson May 20 '20 at 11:24
  • I'd guess it only seemed to work before because the explict `--testPathPattern` overrode the broken input. The error in your title seems pretty clear, your input doesn't make sense as a test pattern. – jonrsharpe May 20 '20 at 11:25
  • At least you're now down to an error that makes some sense though, surely? It's actually complaining about the thing you thought would be the test pattern. Try just `-long.spec.js`, it's a **regex** not a glob, so a bare `*` doesn't make sense. Jest will already match any `.spec.js` anyway, so the pattern is redundant in the "all" option. – jonrsharpe May 20 '20 at 11:30
  • Why would the new suggestion help? It's still not a valid regex, what's the asterisk repeating? Again, just literally use `-long.spec.js` – jonrsharpe May 20 '20 at 11:42
  • 1
    That doesn't quite get there, but this does - thanks for the pointer @jonrsharpe `"cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" vue-cli-service test:unit \".*-long\\.spec\\.js\""` – Keith Jackson May 20 '20 at 11:45

0 Answers0