Skip to content

Commit

Permalink
missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck committed Aug 22, 2023
1 parent 985ddfe commit 73ebcc8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/socket-npm-fixtures/lacking-typosquat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dependencies": {
}
}
40 changes: 40 additions & 0 deletions test/socket-npm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import assert from 'node:assert/strict'
import { spawnSync } from 'node:child_process'
import { describe, it } from 'node:test'
import { fileURLToPath } from 'node:url'

const entryPath = fileURLToPath(new URL('../cli.js', import.meta.url))

/**
* Run relative to current file
*
* @param {object} param0
* @param {string} param0.cwd
* @param {string[]} [param0.args]
* @param {import('node:child_process').ProcessEnvOptions['env'] | undefined} [param0.env]
* @returns {import('node:child_process').SpawnSyncReturns<string>}
*/
function spawnNPM ({ cwd, args = [], env }) {
const pwd = fileURLToPath(new URL(cwd, import.meta.url))
return spawnSync(process.execPath, [entryPath, 'npm', ...args], {
cwd: pwd,
encoding: 'utf-8',
env: {
...(env ?? process.env),
// make sure we don't borrow TTY from parent
SOCKET_SECURITY_TTY_IPC: undefined
},
stdio: ['pipe', 'pipe', 'pipe']
})
}

describe('Socket npm wrapper', () => {
it('should bail on new typosquat', () => {
const ret = spawnNPM({
cwd: './socket-npm-fixtures/lacking-typosquat',
args: ['i', 'bowserify']
})
assert.equal(ret.status, 1)
assert.match(ret.stderr, /Unable to prompt/)
})
})

0 comments on commit 73ebcc8

Please sign in to comment.