command.executableSubcommand.lookup.test.js
This file
Path
tests/command.executableSubcommand.lookup.test.js
113 lines · 4.5 KiB · JavaScript
Last changed by
Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
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);Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 5why, one step back5const { test, describe } = require('node:test');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 6why, one step back6const 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–16why, one step back15const pm = path.join(__dirname, './fixtures/pm');16Add 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 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
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 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
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 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
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 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
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 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
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 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
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 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
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 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 69why, one step back69Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 70–77why, one step back70 testOrSkipOnWindows(71 'when subcommand file is symlink then lookup succeeds',72 async () => {73 const pmlink = path.join(__dirname, 'fixtures', 'pmlink');74 const { stdout } = await execFileAsync('node', [pmlink, 'install']);75 assert.equal(stdout, 'install\n');76 },77 );update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 78why, one step back78Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 79–86why, one step back79 testOrSkipOnWindows(80 'when subcommand file is double symlink then lookup succeeds',81 async () => {82 const pmlink = path.join(__dirname, 'fixtures', 'another-dir', 'pm');83 const { stdout } = await execFileAsync('node', [pmlink, 'install']);84 assert.equal(stdout, 'install\n');85 },86 );update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 87why, one step back87Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 88–95why, one step back88 test('when subcommand suffix is .ts then lookup succeeds', async () => {89 // We support looking for ts files for ts-node in particular, but don't need to test ts-node itself.90 // The subcommand is both plain JavaScript code for this test.91 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');92 // childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], function(_error, stdout, stderr) {93 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-ts']);94 assert.equal(stdout, 'found .ts\n');95 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 96why, one step back96Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 97–101why, one step back97 test('when subcommand suffix is .cjs then lookup succeeds', async () => {98 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');99 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-cjs']);100 assert.equal(stdout, 'found .cjs\n');101 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 102why, one step back102Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 103–107why, one step back103 test('when subcommand suffix is .mjs then lookup succeeds', async () => {104 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');105 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-mjs']);106 assert.equal(stdout, 'found .mjs\n');107 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 108why, one step back108Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 109–112why, one step back109 test('when subsubcommand then lookup sub-sub-command', async () => {110 const { stdout } = await execFileAsync('node', [pm, 'cache', 'clear']);111 assert.equal(stdout, 'cache-clear\n');112 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 113why, one step back113});