command.executableSubcommand.lookup.test.js
This file
Path
tests/command.executableSubcommand.lookup.test.js
111 lines · 4.3 KiB · JavaScript
Last changed by
Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
History of this fileTake it
The walk stopped after 200 commits: lines older than b2842dc point at it.
update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 1–4why, one step back1const childProcess = require('child_process');2const path = require('path');3const util = require('util');4const execFileAsync = util.promisify(childProcess.execFile);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 5–6why, one step back5const { test } = require('node:test');6const assert = require('node:assert/strict');update chinese readme (#1727)wenjiebefore adoptionb2842dc
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;update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 15–20why, one step back15const pm = path.join(__dirname, './fixtures/pm');1617test('when subcommand file missing then error', () => {18 return execFileAsync('node', [pm, 'list']).catch((err) => {19 if (process.platform === 'win32') {20 // Get uncaught thrown error on WindowsSwitch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 21why, one step back21 assert.ok(err.stderr !== undefined);update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 22why, one step back22 } else {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 23why, one step back23 assert.match(err.stderr, /Error: 'pm-list' does not exist/);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 24–31why, one step back24 }25 });26});2728test('when alias subcommand file missing then error', () => {29 return execFileAsync('node', [pm, 'lst']).catch((err) => {30 if (process.platform === 'win32') {31 // Get uncaught thrown error on WindowsSwitch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 32why, one step back32 assert.ok(err.stderr !== undefined);update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 33why, one step back33 } else {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 34why, one step back34 assert.match(err.stderr, /Error: 'pm-list' does not exist/);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 35–38why, one step back35 }36 });37});38Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 39why, one step back39test('when subcommand file has no suffix then lookup succeeds', async () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 40why, one step back40 const { stdout } = await execFileAsync('node', [pm, 'install']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 41why, one step back41 assert.equal(stdout, 'install\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 42–43why, one step back42});43Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 44why, one step back44test('when alias subcommand file has no suffix then lookup succeeds', async () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 45why, one step back45 const { stdout } = await execFileAsync('node', [pm, 'i']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 46why, one step back46 assert.equal(stdout, 'install\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 47–48why, one step back47});48Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 49why, one step back49test('when subcommand target executablefile has no suffix then lookup succeeds', async () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 50why, one step back50 const { stdout } = await execFileAsync('node', [pm, 'specifyInstall']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 51why, one step back51 assert.equal(stdout, 'install\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 52–53why, one step back52});53Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 54why, one step back54test('when subcommand file suffix .js then lookup succeeds', async () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 55why, one step back55 const { stdout } = await execFileAsync('node', [pm, 'publish']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 56why, one step back56 assert.equal(stdout, 'publish\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 57–58why, one step back57});58Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 59why, one step back59test('when alias subcommand file suffix .js then lookup succeeds', async () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 60why, one step back60 const { stdout } = await execFileAsync('node', [pm, 'p']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 61why, one step back61 assert.equal(stdout, 'publish\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 62–63why, one step back62});63Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 64why, one step back64test('when subcommand target executablefile has suffix .js then lookup succeeds', async () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 65why, one step back65 const { stdout } = await execFileAsync('node', [pm, 'specifyPublish']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 66why, one step back66 assert.equal(stdout, 'publish\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 67–68why, one step back67});68Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 69–73why, one step back69testOrSkipOnWindows(70 'when subcommand file is symlink then lookup succeeds',71 async () => {72 const pmlink = path.join(__dirname, 'fixtures', 'pmlink');73 const { stdout } = await execFileAsync('node', [pmlink, 'install']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 74why, one step back74 assert.equal(stdout, 'install\n');Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 75–76why, one step back75 },76);update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 77why, one step back77Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 78–82why, one step back78testOrSkipOnWindows(79 'when subcommand file is double symlink then lookup succeeds',80 async () => {81 const pmlink = path.join(__dirname, 'fixtures', 'another-dir', 'pm');82 const { stdout } = await execFileAsync('node', [pmlink, 'install']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 83why, one step back83 assert.equal(stdout, 'install\n');Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 84–85why, one step back84 },85);update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 86why, one step back86Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 87why, one step back87test('when subcommand suffix is .ts then lookup succeeds', async () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 88–92why, one step back88 // We support looking for ts files for ts-node in particular, but don't need to test ts-node itself.89 // The subcommand is both plain JavaScript code for this test.90 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');91 // childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], function(_error, stdout, stderr) {92 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-ts']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 93why, one step back93 assert.equal(stdout, 'found .ts\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 94–95why, one step back94});95Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 96why, one step back96test('when subcommand suffix is .cjs then lookup succeeds', async () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 97–98why, one step back97 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');98 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-cjs']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 99why, one step back99 assert.equal(stdout, 'found .cjs\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 100–101why, one step back100});101Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 102why, one step back102test('when subcommand suffix is .mjs then lookup succeeds', async () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 103–104why, one step back103 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');104 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-mjs']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 105why, one step back105 assert.equal(stdout, 'found .mjs\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 106–107why, one step back106});107Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 108why, one step back108test('when subsubcommand then lookup sub-sub-command', async () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 109why, one step back109 const { stdout } = await execFileAsync('node', [pm, 'cache', 'clear']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 110why, one step back110 assert.equal(stdout, 'cache-clear\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 111why, one step back111});