Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"scripts": {
"clean": "tsc --build --clean",
"build": "tsc --build --verbose --listEmittedFiles",
"pretest:unit": "tsc --build test --verbose --listEmittedFiles",
"test:unit": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"test:unit": "node --test test/test.js test/e2e.test.js",
"test": "pnpm run build && pnpm run test:unit",
"prepublishOnly": "pnpm run build"
},
Expand All @@ -34,19 +33,13 @@
"cmd-extension": "^1.0.2"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^18.19.87",
"jest": "^29.7.0",
"memfs": "^3.5.3",
"tempy": "^1.0.1",
"typescript": "^4.9.5"
},
"engines": {
"node": ">=22.13"
},
"jest": {
"testEnvironment": "node",
"transform": {}
},
"packageManager": "pnpm@11.0.0-beta.2"
}
2,325 changes: 15 additions & 2,310 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

26 changes: 17 additions & 9 deletions test/e2e.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import fs from 'node:fs'
import path from 'node:path'
import { describe, test, snapshot } from 'node:test'
import assert from 'node:assert/strict'
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

Unused import: assert is imported but never used in this file. Removing it will keep the test file tidy and avoid unused-import lint warnings if linting is added/enabled later.

Suggested change
import assert from 'node:assert/strict'

Copilot uses AI. Check for mistakes.

snapshot.setDefaultSnapshotSerializers([
(value) => typeof value === 'string' ? `\n${value.replaceAll('\r', '')}` : JSON.stringify(value),
])
import tempy from 'tempy'
import { cmdShim } from '../index.js'

const testOnWindows = process.platform === 'win32' ? test : test.skip
const describeOnWindows = process.platform === 'win32' ? describe : describe.skip

testOnWindows('create a command shim for a .exe file', async () => {
const tempDir = tempy.directory()
fs.writeFileSync(path.join(tempDir, 'foo.exe'), '', 'utf8')
await cmdShim(path.join(tempDir, 'foo'), path.join(tempDir, 'dest'))
const stripMarker = (s) => s.replace(/# cmd-shim-target=.*\n/, '')
expect(stripMarker(fs.readFileSync(path.join(tempDir, 'dest'), 'utf-8'))).toMatchSnapshot()
expect(fs.readFileSync(path.join(tempDir, 'dest.cmd'), 'utf-8')).toMatchSnapshot()
expect(fs.readFileSync(path.join(tempDir, 'dest.ps1'), 'utf-8')).toMatchSnapshot()
describeOnWindows('create a command shim for a .exe file', () => {
test('shim files', async (t) => {
const tempDir = tempy.directory()
fs.writeFileSync(path.join(tempDir, 'foo.exe'), '', 'utf8')
await cmdShim(path.join(tempDir, 'foo'), path.join(tempDir, 'dest'))
const stripMarker = (s) => s.replace(/# cmd-shim-target=.*\n/, '')
t.assert.snapshot(stripMarker(fs.readFileSync(path.join(tempDir, 'dest'), 'utf-8')))
t.assert.snapshot(fs.readFileSync(path.join(tempDir, 'dest.cmd'), 'utf-8'))
t.assert.snapshot(fs.readFileSync(path.join(tempDir, 'dest.ps1'), 'utf-8'))
})
})
21 changes: 11 additions & 10 deletions test/__snapshots__/e2e.test.js.snap → test/e2e.test.js.snapshot
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`create a command shim for a .exe file > shim files 1`] = `

exports[`create a command shim for a .exe file 1`] = `
"#!/bin/sh
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
Expand All @@ -14,17 +13,19 @@ esac

"$basedir/foo" "$@"
exit $?
"

`;

exports[`create a command shim for a .exe file 2`] = `
"@SETLOCAL
exports[`create a command shim for a .exe file > shim files 2`] = `

@SETLOCAL
@"%~dp0\\foo" %*
"

`;

exports[`create a command shim for a .exe file 3`] = `
"#!/usr/bin/env pwsh
exports[`create a command shim for a .exe file > shim files 3`] = `

#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent

$exe=""
Expand All @@ -40,5 +41,5 @@ if ($MyInvocation.ExpectingInput) {
& "$basedir/foo" $args
}
exit $LASTEXITCODE
"

`;
12 changes: 6 additions & 6 deletions test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ const fixtureFiles = {
}
}

beforeAll(() => {
const fs = memfs.promises
return Promise.all(
export async function setupFixtures () {
const fsPromises = memfs.promises
await Promise.all(
Object.entries(fixtureFiles).map(async ([dir, files]) => {
await fs.mkdir(dir, { recursive: true })
await fsPromises.mkdir(dir, { recursive: true })
return Promise.all(
Object.entries(files).map(([filename, contents]) => {
return fs.writeFile(path.join(dir, filename), contents)
return fsPromises.writeFile(path.join(dir, filename), contents)
})
)
})
)
})
}
Loading
Loading