Skip to content

Commit

Permalink
Do not install bun on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Sep 12, 2023
1 parent 62230f9 commit e586f85
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 128 deletions.
106 changes: 0 additions & 106 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"lint:lockfile": "lockfile-lint",
"lint:markdown": "markdownlint \"**/*.md\" --ignore node_modules --ignore build --config .markdownlint.js",
"lint:src": "eslint --cache --cache-location node_modules/.cache/.eslintcache --ignore-path .gitignore --report-unused-disable-directives .",
"prepare": "husky install",
"prepare": "husky install && bash test/bun-setup.sh",
"prepublishOnly": "npm run build",
"prettier": "prettier .",
"test": "mocha test test/package-managers/*",
Expand Down Expand Up @@ -116,7 +116,6 @@
"@types/update-notifier": "^6.0.4",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"bun": "^1.0.0",
"c8": "^7.14.0",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
Expand Down
12 changes: 12 additions & 0 deletions test/bun-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Install bun if not installed.
# Must be run in a prepare script instead of devDependencies to avoid npm install failing on Windows.
bun -v &> /dev/null
BUN_EXISTS="$?"

if [ $BUN_EXISTS -ne 0 ]; then
npm install -g bun
fi

# Always return success, even if the install script fails.
# Windows is expected to fail and the bun tests will be skipped.
exit 0
22 changes: 13 additions & 9 deletions test/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const testPass = ({ packageManager }: { packageManager: PackageManagerName }) =>

// touch yarn.lock
// yarn.lock is necessary otherwise yarn sees the package.json in the npm-check-updates directory and throws an error.
if (packageManager === 'yarn') {
if (packageManager === 'yarn' || packageManager === 'bun') {
await fs.writeFile(lockfilePath, '')
}

Expand Down Expand Up @@ -84,14 +84,17 @@ const testPass = ({ packageManager }: { packageManager: PackageManagerName }) =>
rimraf.sync(path.join(cwd, '.pnp.js'))
}

// bun prints the run header to stderr instead of stdout
if (packageManager === 'bun') {
stripAnsi(stderr).should.equal('$ echo Success\n\n$ echo Success\n\n')
} else {
stderr.should.equal('')
}

// stdout should include normal output
stderr.should.equal('')
stripAnsi(stdout).should.containIgnoreCase('Tests pass')
stripAnsi(stdout).should.containIgnoreCase('ncu-test-v2 ~1.0.0 → ~2.0.0')

// stderr should include first failing upgrade
stderr.should.equal('')

// package file should include upgrades
pkgUpgraded.should.containIgnoreCase('"ncu-test-v2": "~2.0.0"')
})
Expand Down Expand Up @@ -459,9 +462,10 @@ else {
testFail({ packageManager: 'yarn' })
})

describe('bun', () => {
// TODO: fix doctor bun tests
// testPass({ packageManager: 'bun' })
// testFail({ packageManager: 'bun' })
// Bun not yet supported on Windows
const describeSkipWindows = os.platform() === 'win32' ? describe.skip : describe
describeSkipWindows('bun', () => {
testPass({ packageManager: 'bun' })
testFail({ packageManager: 'bun' })
})
})
21 changes: 10 additions & 11 deletions test/package-managers/bun/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ chai.use(chaiString)
process.env.NCU_TESTS = 'true'

// Bun not yet supported on Windows
if (os.platform() !== 'win32') {
describe('bun', function () {
it('list', async () => {
const result = await bun.list({ cwd: __dirname })
result.should.have.property('ncu-test-v2')
})
const describeSkipWindows = os.platform() === 'win32' ? describe.skip : describe
describeSkipWindows('bun', function () {
it('list', async () => {
const result = await bun.list({ cwd: __dirname })
result.should.have.property('ncu-test-v2')
})

it('latest', async () => {
const { version } = await bun.latest('ncu-test-v2', '1.0.0', { cwd: __dirname })
version!.should.equal('2.0.0')
})
it('latest', async () => {
const { version } = await bun.latest('ncu-test-v2', '1.0.0', { cwd: __dirname })
version!.should.equal('2.0.0')
})
}
})

0 comments on commit e586f85

Please sign in to comment.