Skip to content

Commit 0b6fd4f

Browse files
author
Charan Sarin
committed
Fixed failing tests due to concurrent cache access, instable package registry access and missing shell env.
1 parent b712199 commit 0b6fd4f

File tree

18 files changed

+51
-9
lines changed

18 files changed

+51
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/coverage
55
/.eslintcache
66
/.dccache
7+
/test/_yarn_cache

.taprc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"timeout": 30,
33
"reporter": "spec"
4-
}
4+
}

bin/cli-install.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,16 @@ const ensureGitClone = async (remote, local) => {
5757
*/
5858
const yarnInstall = (local) => {
5959
const dir = absoluteRepoPath(local)
60-
return run('yarn', ['install'], dir)
60+
/* c8 ignore start */
61+
const args = process.env.TAP
62+
? [
63+
'install',
64+
'--offline',
65+
`--cache-folder ../../../../_yarn_cache/.yarn_${process.env.TAP_CHILD_ID}`
66+
]
67+
: ['install']
68+
/* c8 ignore stop */
69+
return run('yarn', args, dir)
6170
}
6271

6372
/**

src/utils.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export const gitStatus = (dir) => {
8383
const firstLine = lines[0]
8484

8585
const br = firstLine.match(/##\s+(\w+)/)
86-
const branch = (br && String(br[1])) || ''
86+
87+
const branch =
88+
(br && String(br[1])) || /* c8 ignore start */ '' /* c8 ignore stop */
8789

8890
const b = firstLine.match(/behind\s+(\d+)/)
8991
const behind = (b && Number(b[1])) || 0

test/_fixtures/addrepos/.yarnrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarn-offline-mirror "../../npm-packages-offline-cache"
2+
yarn-offline-mirror-pruning true

test/_fixtures/empty/.yarnrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarn-offline-mirror "../../npm-packages-offline-cache"
2+
yarn-offline-mirror-pruning true

test/_fixtures/listrepos/.yarnrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarn-offline-mirror "../../npm-packages-offline-cache"
2+
yarn-offline-mirror-pruning true

test/_fixtures/norepos/.yarnrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarn-offline-mirror "../../npm-packages-offline-cache"
2+
yarn-offline-mirror-pruning true

test/_fixtures/pullrepos/.yarnrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarn-offline-mirror "../../npm-packages-offline-cache"
2+
yarn-offline-mirror-pruning true

test/_fixtures/runrepos/.yarnrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarn-offline-mirror "../../npm-packages-offline-cache"
2+
yarn-offline-mirror-pruning true

test/cli-install.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import path from 'path'
22
import fs from 'fs-extra'
33
import tap from 'tap'
4-
import { cli, stubGit, cleanupGit } from './helper.js'
4+
import { cli, stubGit, cleanupGit, before } from './helper.js'
5+
6+
tap.before(before)
57

6-
// TODO fix on ci
78
tap.test('$ cli install (on empty directory)', async (t) => {
89
stubGit()
910
const cwd = './test/_fixtures/addrepos'

test/cli-list.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import tap from 'tap'
22
import { promisify } from 'util'
33
import { exec } from 'child_process'
4-
import { cli, stubGit, cleanupGit } from './helper.js'
4+
import { cli, stubGit, cleanupGit, before } from './helper.js'
55
import { root } from '../src/utils.js'
66

77
const execPromise = promisify(exec)
88

9+
tap.before(before)
10+
911
tap.test('$ cli list (on empty directory)', async (t) => {
1012
const result = await cli(['list'], './test/_fixtures/empty')
1113
t.equal(0, result.code, 'Should succeed')

test/cli-pull.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import tap from 'tap'
22
import { promisify } from 'util'
33
import { exec } from 'child_process'
4-
import { cli, stubGit, cleanupGit } from './helper.js'
4+
import { cli, stubGit, cleanupGit, before } from './helper.js'
55
import { root } from '../src/utils.js'
66

77
const execPromise = promisify(exec)
88
const cwd = './test/_fixtures/pullrepos'
99

10+
tap.before(before)
11+
1012
const prepare = async ({ addChanges = false }) => {
1113
if (!addChanges) {
1214
stubGit('pull')

test/cli-run.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import tap from 'tap'
2-
import { cli, stubGit, cleanupGit } from './helper.js'
2+
import { cli, stubGit, cleanupGit, before } from './helper.js'
33
const cwd = './test/_fixtures/runrepos'
44

5+
tap.before(before)
6+
57
const prepare = async () => {
68
stubGit('run')
79
return cli(['install'], cwd)

test/cli.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import tap from 'tap'
2-
import { cli } from './helper.js'
2+
import { cli, before } from './helper.js'
3+
4+
tap.before(before)
35

46
tap.test('$ cli', async (t) => {
57
const result = await cli([])

test/helper.js

+9
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@ export const cleanupGit = (testPhase = 'install') => {
5050
}
5151

5252
export const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
53+
54+
/**
55+
* Set fallback for `process.env.SHELL` as it may be undefined in CI container
56+
* Reason: `yarn --cache-folder` does not work properly without.
57+
* See /src/utils.js (run->spawn)
58+
*/
59+
export const before = () => {
60+
process.env.SHELL = process.env.SHELL || 'sh'
61+
}
21.3 KB
Binary file not shown.
2.95 KB
Binary file not shown.

0 commit comments

Comments
 (0)