@jcoreio/toolchain-mocha 5.3.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.mocharc.cjs CHANGED
@@ -8,14 +8,14 @@ module.exports = {
8
8
  recursive: true,
9
9
  spec: getSpecs(getPluginsArraySync('mochaSpecs')),
10
10
  watchIgnore: ['**/node_modules', '**/.git'],
11
- ...(process.env.JCOREIO_TOOLCHAIN_ESM
12
- ? {
13
- 'node-option': [
14
- 'experimental-default-type=module',
15
- `import=@jcoreio/toolchain-esnext/util/esmLoader.cjs`,
16
- ],
17
- }
18
- : {}),
11
+ ...(process.env.JCOREIO_TOOLCHAIN_ESM ?
12
+ {
13
+ 'node-option': [
14
+ 'experimental-default-type=module',
15
+ `import=@jcoreio/toolchain-esnext/util/esmLoader.cjs`,
16
+ ],
17
+ }
18
+ : {}),
19
19
  ...(process.env.CI ? { forbidOnly: true } : {}),
20
20
  extension: extensions,
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcoreio/toolchain-mocha",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
4
4
  "description": "Mocha build toolchain",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,7 +27,7 @@
27
27
  "nyc": "^15.1.0",
28
28
  "resolve-bin": "^1.0.0",
29
29
  "semver": "^7.5.3",
30
- "@jcoreio/toolchain": "5.3.0"
30
+ "@jcoreio/toolchain": "5.3.2"
31
31
  },
32
32
  "toolchainManaged": {
33
33
  "devDependencies": {
@@ -7,16 +7,16 @@ module.exports = [
7
7
  async function getConfigFiles({ fromVersion }) {
8
8
  return {
9
9
  'nyc.config.cjs': async (existing) =>
10
- existing && fromVersion
11
- ? existing
12
- : dedent`
10
+ existing && fromVersion ? existing : (
11
+ dedent`
13
12
  /* eslint-env node, es2018 */
14
13
  const base = require('${name}/nyc.config.cjs')
15
14
  module.exports = {
16
15
  ...base,
17
16
  }
18
17
 
19
- `,
18
+ `
19
+ ),
20
20
  '.mocharc.cjs': async (existing) => {
21
21
  if (existing && fromVersion) return existing
22
22
  const specs = []
@@ -2,12 +2,26 @@ const execa = require('@jcoreio/toolchain/util/execa.cjs')
2
2
  const {
3
3
  toolchainPackages,
4
4
  toolchainConfig,
5
+ isMonorepoRoot,
6
+ monorepoSubpackageDirs,
7
+ projectDir,
5
8
  } = require('@jcoreio/toolchain/util/findUps.cjs')
9
+ const fs = require('@jcoreio/toolchain/util/projectFs.cjs')
10
+ const path = require('path')
6
11
 
7
12
  const testScripts = Object.entries(toolchainConfig.scripts || {}).filter(
8
13
  ([name]) => /^test\W/.test(name)
9
14
  )
10
15
 
16
+ const getFileArgs = async (args) =>
17
+ (
18
+ await Promise.all(
19
+ args.map(async (arg) =>
20
+ !arg.startsWith('-') && (await fs.pathExists(arg)) ? [arg] : []
21
+ )
22
+ )
23
+ ).flat()
24
+
11
25
  const makeScripts = ({
12
26
  suffix = '',
13
27
  env = process.env,
@@ -29,9 +43,9 @@ const makeScripts = ({
29
43
  `coverage${name.substring(4)}${suffix}`,
30
44
  {
31
45
  description: `${
32
- typeof value.description === 'string'
33
- ? value.description
34
- : `run ${name}`
46
+ typeof value.description === 'string' ?
47
+ value.description
48
+ : `run ${name}`
35
49
  }${descriptionSuffix} with code coverage`,
36
50
  run: async (args = []) => {
37
51
  await execa('nyc', ['tc', name, ...args], {
@@ -47,6 +61,43 @@ const makeScripts = ({
47
61
  [`test${suffix}`]: {
48
62
  description: `run all tests${descriptionSuffix}`,
49
63
  run: async (args = []) => {
64
+ if (isMonorepoRoot) {
65
+ const fileArgs = await getFileArgs(args)
66
+ const subpackageDirs = new Set(
67
+ fileArgs.map((file) =>
68
+ monorepoSubpackageDirs.find(
69
+ (dir) =>
70
+ !path
71
+ .relative(
72
+ path.resolve(projectDir, dir),
73
+ path.resolve(projectDir, file)
74
+ )
75
+ .startsWith('.')
76
+ )
77
+ )
78
+ )
79
+ const subpackageDir =
80
+ subpackageDirs.size === 1 ? [...subpackageDirs][0] : undefined
81
+
82
+ if (subpackageDir) {
83
+ await execa(
84
+ 'tc',
85
+ [
86
+ 'test',
87
+ ...args.map((arg) => {
88
+ if (!fs.pathExistsSync(arg)) return arg
89
+ return path.relative(
90
+ path.resolve(projectDir, subpackageDir),
91
+ path.resolve(projectDir, arg)
92
+ )
93
+ }),
94
+ ],
95
+ { env, cwd: subpackageDir }
96
+ )
97
+ return
98
+ }
99
+ }
100
+
50
101
  if (testScripts.length) {
51
102
  for (const [name] of testScripts) {
52
103
  await execa('tc', [name, ...args], { env })