command.executableSubcommand.lookup.test.js
This file
Path
tests/command.executableSubcommand.lookup.test.js
116 lines · 4.5 KiB · JavaScript
Last changed by
Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
History of this fileTake it
The walk stopped after 200 commits: lines older than 9864529 point at it.
Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 1–12why, 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.7// This file does end-to-end tests actually spawning program.8// See also command.executableSubcommand.search.test.js910// Suppress false positive warnings due to use of testOrSkipOnWindows11/* eslint-disable jest/no-standalone-expect */12Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 13why, one step back13const testOrSkipOnWindows = process.platform === 'win32' ? test.skip : test;Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 14–43why, one step back14const 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});43Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 44why, one step back44test('when subcommand file has no suffix then lookup succeeds', async () => {Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 45–48why, one step back45 const { stdout } = await execFileAsync('node', [pm, 'install']);46 expect(stdout).toBe('install\n');47});48Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 49why, one step back49test('when alias subcommand file has no suffix then lookup succeeds', async () => {Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 50–53why, one step back50 const { stdout } = await execFileAsync('node', [pm, 'i']);51 expect(stdout).toBe('install\n');52});53Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 54why, one step back54test('when subcommand target executablefile has no suffix then lookup succeeds', async () => {Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 55–58why, one step back55 const { stdout } = await execFileAsync('node', [pm, 'specifyInstall']);56 expect(stdout).toBe('install\n');57});58Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 59why, one step back59test('when subcommand file suffix .js then lookup succeeds', async () => {Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 60–63why, one step back60 const { stdout } = await execFileAsync('node', [pm, 'publish']);61 expect(stdout).toBe('publish\n');62});63Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 64why, one step back64test('when alias subcommand file suffix .js then lookup succeeds', async () => {Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 65–68why, one step back65 const { stdout } = await execFileAsync('node', [pm, 'p']);66 expect(stdout).toBe('publish\n');67});68Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 69why, one step back69test('when subcommand target executablefile has suffix .js then lookup succeeds', async () => {Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 70–73why, one step back70 const { stdout } = await execFileAsync('node', [pm, 'specifyPublish']);71 expect(stdout).toBe('publish\n');72});73Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 74–81why, one step back74testOrSkipOnWindows(75 'when subcommand file is symlink then lookup succeeds',76 async () => {77 const pmlink = path.join(__dirname, 'fixtures', 'pmlink');78 const { stdout } = await execFileAsync('node', [pmlink, 'install']);79 expect(stdout).toBe('install\n');80 },81);Add another PR to CHANGELOGJohn Geebefore adoption9864529
line 82why, one step back82Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 83–90why, one step back83testOrSkipOnWindows(84 'when subcommand file is double symlink then lookup succeeds',85 async () => {86 const pmlink = path.join(__dirname, 'fixtures', 'another-dir', 'pm');87 const { stdout } = await execFileAsync('node', [pmlink, 'install']);88 expect(stdout).toBe('install\n');89 },90);Add another PR to CHANGELOGJohn Geebefore adoption9864529
line 91why, one step back91Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 92why, one step back92test('when subcommand suffix is .ts then lookup succeeds', async () => {Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 93–100why, one step back93 // We support looking for ts files for ts-node in particular, but don't need to test ts-node itself.94 // The subcommand is both plain JavaScript code for this test.95 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');96 // childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], function(_error, stdout, stderr) {97 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-ts']);98 expect(stdout).toBe('found .ts\n');99});100Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 101why, one step back101test('when subcommand suffix is .cjs then lookup succeeds', async () => {Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 102–106why, one step back102 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');103 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-cjs']);104 expect(stdout).toBe('found .cjs\n');105});106Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 107why, one step back107test('when subcommand suffix is .mjs then lookup succeeds', async () => {Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 108–112why, one step back108 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');109 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-mjs']);110 expect(stdout).toBe('found .mjs\n');111});112Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 113why, one step back113test('when subsubcommand then lookup sub-sub-command', async () => {Add another PR to CHANGELOGJohn Geebefore adoption9864529
lines 114–116why, one step back114 const { stdout } = await execFileAsync('node', [pm, 'cache', 'clear']);115 expect(stdout).toBe('cache-clear\n');116});