command.executableSubcommand.lookup.test.js
This file
Path
tests/command.executableSubcommand.lookup.test.js
110 lines · 4.4 KiB · JavaScript
Last changed by
Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
History of this fileTake it
The walk stopped after 200 commits: lines older than 0b0fbbe point at it.
Update dependencies (#1524)John Geebefore adoption0b0fbbe
lines 1–6why, one step back1const childProcess = require('child_process');2const path = require('path');3const util = require('util');4const execFileAsync = util.promisify(childProcess.execFile);56// Calling node explicitly so pm works without file suffix cross-platform.Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
lines 7–8why, one step back7// This file does end-to-end tests actually spawning program.8// See also command.executableSubcommand.search.test.jsUpdate dependencies (#1524)John Geebefore adoption0b0fbbe
line 9why, one step back9Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 10why, one step back10// Suppress false positive warnings due to use of testOrSkipOnWindowsUpdate dependencies (#1524)John Geebefore adoption0b0fbbe
lines 11–110why, one step back11/* eslint-disable jest/no-standalone-expect */1213const testOrSkipOnWindows = (process.platform === 'win32') ? test.skip : test;14const pm = path.join(__dirname, './fixtures/pm');1516test('when subcommand file missing then error', () => {17 expect.assertions(1);18 return execFileAsync('node', [pm, 'list']).catch((err) => {19 if (process.platform === 'win32') {20 // Get uncaught thrown error on Windows21 // eslint-disable-next-line jest/no-conditional-expect22 expect(err.stderr).toBeDefined();23 } else {24 // eslint-disable-next-line jest/no-conditional-expect25 expect(err.stderr).toMatch(/Error: 'pm-list' does not exist/);26 }27 });28});2930test('when alias subcommand file missing then error', () => {31 expect.assertions(1);32 return execFileAsync('node', [pm, 'lst']).catch((err) => {33 if (process.platform === 'win32') {34 // Get uncaught thrown error on Windows35 // eslint-disable-next-line jest/no-conditional-expect36 expect(err.stderr).toBeDefined();37 } else {38 // eslint-disable-next-line jest/no-conditional-expect39 expect(err.stderr).toMatch(/Error: 'pm-list' does not exist/);40 }41 });42});4344test('when subcommand file has no suffix then lookup succeeds', async() => {45 const { stdout } = await execFileAsync('node', [pm, 'install']);46 expect(stdout).toBe('install\n');47});4849test('when alias subcommand file has no suffix then lookup succeeds', async() => {50 const { stdout } = await execFileAsync('node', [pm, 'i']);51 expect(stdout).toBe('install\n');52});5354test('when subcommand target executablefile has no suffix then lookup succeeds', async() => {55 const { stdout } = await execFileAsync('node', [pm, 'specifyInstall']);56 expect(stdout).toBe('install\n');57});5859test('when subcommand file suffix .js then lookup succeeds', async() => {60 const { stdout } = await execFileAsync('node', [pm, 'publish']);61 expect(stdout).toBe('publish\n');62});6364test('when alias subcommand file suffix .js then lookup succeeds', async() => {65 const { stdout } = await execFileAsync('node', [pm, 'p']);66 expect(stdout).toBe('publish\n');67});6869test('when subcommand target executablefile has suffix .js then lookup succeeds', async() => {70 const { stdout } = await execFileAsync('node', [pm, 'specifyPublish']);71 expect(stdout).toBe('publish\n');72});7374testOrSkipOnWindows('when subcommand file is symlink then lookup succeeds', async() => {75 const pmlink = path.join(__dirname, 'fixtures', 'pmlink');76 const { stdout } = await execFileAsync('node', [pmlink, 'install']);77 expect(stdout).toBe('install\n');78});7980testOrSkipOnWindows('when subcommand file is double symlink then lookup succeeds', async() => {81 const pmlink = path.join(__dirname, 'fixtures', 'another-dir', 'pm');82 const { stdout } = await execFileAsync('node', [pmlink, 'install']);83 expect(stdout).toBe('install\n');84});8586test('when subcommand suffix is .ts then lookup succeeds', async() => {87 // We support looking for ts files for ts-node in particular, but don't need to test ts-node itself.88 // The subcommand is both plain JavaScript code for this test.89 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');90 // childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], function(_error, stdout, stderr) {91 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-ts']);92 expect(stdout).toBe('found .ts\n');93});9495test('when subcommand suffix is .cjs then lookup succeeds', async() => {96 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');97 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-cjs']);98 expect(stdout).toBe('found .cjs\n');99});100101test('when subcommand suffix is .mjs then lookup succeeds', async() => {102 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');103 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-mjs']);104 expect(stdout).toBe('found .mjs\n');105});106107test('when subsubcommand then lookup sub-sub-command', async() => {108 const { stdout } = await execFileAsync('node', [pm, 'cache', 'clear']);109 expect(stdout).toBe('cache-clear\n');110});