Skip to content
Myr

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 file

Take 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 back
1const 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 */12

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 14–43why, one step back
14const 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});43

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 45–48why, one step back
45 const { stdout } = await execFileAsync('node', [pm, 'install']);
46 expect(stdout).toBe('install\n');47});48

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 50–53why, one step back
50 const { stdout } = await execFileAsync('node', [pm, 'i']);
51 expect(stdout).toBe('install\n');52});53

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 55–58why, one step back
55 const { stdout } = await execFileAsync('node', [pm, 'specifyInstall']);
56 expect(stdout).toBe('install\n');57});58

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 60–63why, one step back
60 const { stdout } = await execFileAsync('node', [pm, 'publish']);
61 expect(stdout).toBe('publish\n');62});63

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 65–68why, one step back
65 const { stdout } = await execFileAsync('node', [pm, 'p']);
66 expect(stdout).toBe('publish\n');67});68

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 70–73why, one step back
70 const { stdout } = await execFileAsync('node', [pm, 'specifyPublish']);
71 expect(stdout).toBe('publish\n');72});73

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 74–81why, one step back
74testOrSkipOnWindows(
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 back
82

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 83–90why, one step back
83testOrSkipOnWindows(
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 back
91

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 93–100why, one step back
93 // 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});100

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 102–106why, one step back
102 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});106

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 108–112why, one step back
108 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});112

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add another PR to CHANGELOGJohn Geebefore adoption9864529

lines 114–116why, one step back
114 const { stdout } = await execFileAsync('node', [pm, 'cache', 'clear']);
115 expect(stdout).toBe('cache-clear\n');116});