command.executableSubcommand.lookup.test.js
This file
Path
tests/command.executableSubcommand.lookup.test.js
131 lines · 4.8 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 1–3why, one step back1import * as childProcess from 'child_process';2import * as path from 'path';3import * as util from 'util';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 4why, one step back4const execFileAsync = util.promisify(childProcess.execFile);Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 5–6why, one step back5import { test, describe } from 'node:test';6import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 7–13why, one step back78// Calling node explicitly so pm works without file suffix cross-platform.9// This file does end-to-end tests actually spawning program.10// See also command.executableSubcommand.search.test.js1112// Suppress false positive warnings due to use of testOrSkipOnWindows13Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 14why, one step back14const testOrSkipOnWindows = process.platform === 'win32' ? test.skip : test;Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 15why, one step back15const pm = path.join(import.meta.dirname, './fixtures/pm');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 16why, one step back16Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 17–26why, one step back17describe('executable subcommand lookup ', () => {18 test('when subcommand file missing then error', () => {19 return execFileAsync('node', [pm, 'list']).catch((err) => {20 if (process.platform === 'win32') {21 // Get uncaught thrown error on Windows22 assert.ok(err.stderr !== undefined);23 } else {24 assert.match(err.stderr, /Error: 'pm-list' does not exist/);25 }26 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 27–28why, one step back27 });28Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 29–37why, one step back29 test('when alias subcommand file missing then error', () => {30 return execFileAsync('node', [pm, 'lst']).catch((err) => {31 if (process.platform === 'win32') {32 // Get uncaught thrown error on Windows33 assert.ok(err.stderr !== undefined);34 } else {35 assert.match(err.stderr, /Error: 'pm-list' does not exist/);36 }37 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 38–39why, one step back38 });39Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 40–43why, one step back40 test('when subcommand file has no suffix then lookup succeeds', async () => {41 const { stdout } = await execFileAsync('node', [pm, 'install']);42 assert.equal(stdout, 'install\n');43 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 44why, one step back44Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 45–48why, one step back45 test('when alias subcommand file has no suffix then lookup succeeds', async () => {46 const { stdout } = await execFileAsync('node', [pm, 'i']);47 assert.equal(stdout, 'install\n');48 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 49why, one step back49Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 50–53why, one step back50 test('when subcommand target executablefile has no suffix then lookup succeeds', async () => {51 const { stdout } = await execFileAsync('node', [pm, 'specifyInstall']);52 assert.equal(stdout, 'install\n');53 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 54why, one step back54Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 55–58why, one step back55 test('when subcommand file suffix .js then lookup succeeds', async () => {56 const { stdout } = await execFileAsync('node', [pm, 'publish']);57 assert.equal(stdout, 'publish\n');58 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 59why, one step back59Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 60–63why, one step back60 test('when alias subcommand file suffix .js then lookup succeeds', async () => {61 const { stdout } = await execFileAsync('node', [pm, 'p']);62 assert.equal(stdout, 'publish\n');63 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 64why, one step back64Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 65–68why, one step back65 test('when subcommand target executablefile has suffix .js then lookup succeeds', async () => {66 const { stdout } = await execFileAsync('node', [pm, 'specifyPublish']);67 assert.equal(stdout, 'publish\n');68 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 69why, one step back69Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 70–72why, one step back70 testOrSkipOnWindows(71 'when subcommand file is symlink then lookup succeeds',72 async () => {Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 73why, one step back73 const pmlink = path.join(import.meta.dirname, 'fixtures', 'pmlink');Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 74–77why, one step back74 const { stdout } = await execFileAsync('node', [pmlink, 'install']);75 assert.equal(stdout, 'install\n');76 },77 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 78why, one step back78Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 79–81why, one step back79 testOrSkipOnWindows(80 'when subcommand file is double symlink then lookup succeeds',81 async () => {Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 82–87why, one step back82 const pmlink = path.join(83 import.meta.dirname,84 'fixtures',85 'another-dir',86 'pm',87 );Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 88–91why, one step back88 const { stdout } = await execFileAsync('node', [pmlink, 'install']);89 assert.equal(stdout, 'install\n');90 },91 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 92why, one step back92Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 93–94why, one step back93 // This test currently fails on Node 20 when run as ESM because Node does not execute .ts files as JavaScript by default.94 test.skip('when subcommand suffix is .ts then lookup succeeds', async () => {Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 95–96why, one step back95 // We support looking for ts files for ts-node in particular, but don't need to test ts-node itself.96 // The subcommand is both plain JavaScript code for this test.Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 97–101why, one step back97 const binLinkTs = path.join(98 import.meta.dirname,99 'fixtures-extensions',100 'pm.js',101 );Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 102–105why, one step back102 // childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], function(_error, stdout, stderr) {103 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-ts']);104 assert.equal(stdout, 'found .ts\n');105 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 106why, one step back106Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 107why, one step back107 test('when subcommand suffix is .cjs then lookup succeeds', async () => {Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 108–112why, one step back108 const binLinkTs = path.join(109 import.meta.dirname,110 'fixtures-extensions',111 'pm.js',112 );Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 113–115why, one step back113 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-cjs']);114 assert.equal(stdout, 'found .cjs\n');115 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 116why, one step back116Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 117why, one step back117 test('when subcommand suffix is .mjs then lookup succeeds', async () => {Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 118–122why, one step back118 const binLinkTs = path.join(119 import.meta.dirname,120 'fixtures-extensions',121 'pm.js',122 );Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 123–125why, one step back123 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-mjs']);124 assert.equal(stdout, 'found .mjs\n');125 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 126why, one step back126Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 127–130why, one step back127 test('when subsubcommand then lookup sub-sub-command', async () => {128 const { stdout } = await execFileAsync('node', [pm, 'cache', 'clear']);129 assert.equal(stdout, 'cache-clear\n');130 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 131why, one step back131});