Skip to content
Myr

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 file

Take 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 back
1const 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 back
5const { test } = require('node:test');
6const assert = require('node:assert/strict');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 7–13why, one step back
7
8// 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 testOrSkipOnWindows13

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 14why, one step back
14const testOrSkipOnWindows = process.platform === 'win32' ? test.skip : test;

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 15–20why, one step back
15const 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 Windows

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 21why, one step back
21 assert.ok(err.stderr !== undefined);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 22why, one step back
22 } else {

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 23why, one step back
23 assert.match(err.stderr, /Error: 'pm-list' does not exist/);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 24–31why, one step back
24 }
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 Windows

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 32why, one step back
32 assert.ok(err.stderr !== undefined);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 33why, one step back
33 } else {

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 34why, one step back
34 assert.match(err.stderr, /Error: 'pm-list' does not exist/);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 35–38why, one step back
35 }
36 });37});38

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 39why, one step back
39test('when subcommand file has no suffix then lookup succeeds', async () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 40why, one step back
40 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 back
41 assert.equal(stdout, 'install\n');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 42–43why, one step back
42});
43

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 44why, one step back
44test('when alias subcommand file has no suffix then lookup succeeds', async () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 45why, one step back
45 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 back
46 assert.equal(stdout, 'install\n');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 47–48why, one step back
47});
48

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 49why, one step back
49test('when subcommand target executablefile has no suffix then lookup succeeds', async () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 50why, one step back
50 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 back
51 assert.equal(stdout, 'install\n');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 52–53why, one step back
52});
53

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 54why, one step back
54test('when subcommand file suffix .js then lookup succeeds', async () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 55why, one step back
55 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 back
56 assert.equal(stdout, 'publish\n');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 57–58why, one step back
57});
58

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 59why, one step back
59test('when alias subcommand file suffix .js then lookup succeeds', async () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 60why, one step back
60 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 back
61 assert.equal(stdout, 'publish\n');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 62–63why, one step back
62});
63

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 64why, one step back
64test('when subcommand target executablefile has suffix .js then lookup succeeds', async () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 65why, one step back
65 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 back
66 assert.equal(stdout, 'publish\n');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 67–68why, one step back
67});
68

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 69–73why, one step back
69testOrSkipOnWindows(
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 back
74 assert.equal(stdout, 'install\n');

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 75–76why, one step back
75 },
76);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 77why, one step back
77

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 78–82why, one step back
78testOrSkipOnWindows(
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 back
83 assert.equal(stdout, 'install\n');

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 84–85why, one step back
84 },
85);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 86why, one step back
86

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 87why, one step back
87test('when subcommand suffix is .ts then lookup succeeds', async () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 88–92why, one step back
88 // 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 back
93 assert.equal(stdout, 'found .ts\n');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 94–95why, one step back
94});
95

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 96why, one step back
96test('when subcommand suffix is .cjs then lookup succeeds', async () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 97–98why, one step back
97 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 back
99 assert.equal(stdout, 'found .cjs\n');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 100–101why, one step back
100});
101

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 102why, one step back
102test('when subcommand suffix is .mjs then lookup succeeds', async () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 103–104why, one step back
103 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 back
105 assert.equal(stdout, 'found .mjs\n');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 106–107why, one step back
106});
107

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 108why, one step back
108test('when subsubcommand then lookup sub-sub-command', async () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 109why, one step back
109 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 back
110 assert.equal(stdout, 'cache-clear\n');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 111why, one step back
111});