command.executableSubcommand.lookup.test.js
This file
Path
tests/command.executableSubcommand.lookup.test.js
110 lines · 4.4 KiB · JavaScript
Last changed by
Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
History of this fileTake it
The walk stopped after 200 commits: lines older than 733047f point at it.
Add parse result test (#1188)John Geebefore adoption733047f
lines 1–3why, one step back1const childProcess = require('child_process');2const path = require('path');3const util = require('util');Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 4why, one step back4const execFileAsync = util.promisify(childProcess.execFile);Add parse result test (#1188)John Geebefore adoption733047f
lines 5–6why, one step back56// Calling node explicitly so pm works without file suffix cross-platform.Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
lines 7–8why, one step back7// This file does end-to-end tests actually spawning program.8// See also command.executableSubcommand.search.test.jsAdd parse result test (#1188)John Geebefore adoption733047f
line 9why, one step back9Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 10why, one step back10// Suppress false positive warnings due to use of testOrSkipOnWindowsAdd parse result test (#1188)John Geebefore adoption733047f
lines 11–17why, one step back11/* eslint-disable jest/no-standalone-expect */1213const testOrSkipOnWindows = (process.platform === 'win32') ? test.skip : test;14const pm = path.join(__dirname, './fixtures/pm');1516test('when subcommand file missing then error', () => {17 expect.assertions(1);Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 18why, one step back18 return execFileAsync('node', [pm, 'list']).catch((err) => {Add parse result test (#1188)John Geebefore adoption733047f
lines 19–20why, one step back19 if (process.platform === 'win32') {20 // Get uncaught thrown error on WindowsMerge branch 'develop' into release/7.xJohn Geebefore adoptiond90ef12
line 21why, one step back21 // eslint-disable-next-line jest/no-conditional-expectAdd parse result test (#1188)John Geebefore adoption733047f
lines 22–23why, one step back22 expect(err.stderr).toBeDefined();23 } else {Merge branch 'develop' into release/7.xJohn Geebefore adoptiond90ef12
line 24why, one step back24 // eslint-disable-next-line jest/no-conditional-expectUpdate dependencies in 7.x (#1412)John Geebefore adoption469acc9
line 25why, one step back25 expect(err.stderr).toMatch(/Error: 'pm-list' does not exist/);Add parse result test (#1188)John Geebefore adoption733047f
lines 26–31why, one step back26 }27 });28});2930test('when alias subcommand file missing then error', () => {31 expect.assertions(1);Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 32why, one step back32 return execFileAsync('node', [pm, 'lst']).catch((err) => {Add parse result test (#1188)John Geebefore adoption733047f
lines 33–34why, one step back33 if (process.platform === 'win32') {34 // Get uncaught thrown error on WindowsMerge branch 'develop' into release/7.xJohn Geebefore adoptiond90ef12
line 35why, one step back35 // eslint-disable-next-line jest/no-conditional-expectAdd parse result test (#1188)John Geebefore adoption733047f
lines 36–37why, one step back36 expect(err.stderr).toBeDefined();37 } else {Merge branch 'develop' into release/7.xJohn Geebefore adoptiond90ef12
line 38why, one step back38 // eslint-disable-next-line jest/no-conditional-expectUpdate dependencies in 7.x (#1412)John Geebefore adoption469acc9
line 39why, one step back39 expect(err.stderr).toMatch(/Error: 'pm-list' does not exist/);Add parse result test (#1188)John Geebefore adoption733047f
lines 40–44why, one step back40 }41 });42});4344test('when subcommand file has no suffix then lookup succeeds', async() => {Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 45why, one step back45 const { stdout } = await execFileAsync('node', [pm, 'install']);Add parse result test (#1188)John Geebefore adoption733047f
lines 46–49why, one step back46 expect(stdout).toBe('install\n');47});4849test('when alias subcommand file has no suffix then lookup succeeds', async() => {Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 50why, one step back50 const { stdout } = await execFileAsync('node', [pm, 'i']);Add parse result test (#1188)John Geebefore adoption733047f
lines 51–54why, one step back51 expect(stdout).toBe('install\n');52});5354test('when subcommand target executablefile has no suffix then lookup succeeds', async() => {Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 55why, one step back55 const { stdout } = await execFileAsync('node', [pm, 'specifyInstall']);Add parse result test (#1188)John Geebefore adoption733047f
lines 56–59why, one step back56 expect(stdout).toBe('install\n');57});5859test('when subcommand file suffix .js then lookup succeeds', async() => {Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 60why, one step back60 const { stdout } = await execFileAsync('node', [pm, 'publish']);Add parse result test (#1188)John Geebefore adoption733047f
lines 61–64why, one step back61 expect(stdout).toBe('publish\n');62});6364test('when alias subcommand file suffix .js then lookup succeeds', async() => {Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 65why, one step back65 const { stdout } = await execFileAsync('node', [pm, 'p']);Add parse result test (#1188)John Geebefore adoption733047f
lines 66–69why, one step back66 expect(stdout).toBe('publish\n');67});6869test('when subcommand target executablefile has suffix .js then lookup succeeds', async() => {Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 70why, one step back70 const { stdout } = await execFileAsync('node', [pm, 'specifyPublish']);Add parse result test (#1188)John Geebefore adoption733047f
lines 71–75why, one step back71 expect(stdout).toBe('publish\n');72});7374testOrSkipOnWindows('when subcommand file is symlink then lookup succeeds', async() => {75 const pmlink = path.join(__dirname, 'fixtures', 'pmlink');Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 76why, one step back76 const { stdout } = await execFileAsync('node', [pmlink, 'install']);Add parse result test (#1188)John Geebefore adoption733047f
lines 77–81why, one step back77 expect(stdout).toBe('install\n');78});7980testOrSkipOnWindows('when subcommand file is double symlink then lookup succeeds', async() => {81 const pmlink = path.join(__dirname, 'fixtures', 'another-dir', 'pm');Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 82why, one step back82 const { stdout } = await execFileAsync('node', [pmlink, 'install']);Add parse result test (#1188)John Geebefore adoption733047f
lines 83–87why, one step back83 expect(stdout).toBe('install\n');84});8586test('when subcommand suffix is .ts then lookup succeeds', async() => {87 // We support looking for ts files for ts-node in particular, but don't need to test ts-node itself.Add cjs to list of expected node script extensions (#1449)John Geebefore adoptiona28a89b
lines 88–89why, one step back88 // The subcommand is both plain JavaScript code for this test.89 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');Add parse result test (#1188)John Geebefore adoption733047f
line 90why, one step back90 // childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], function(_error, stdout, stderr) {Add cjs to list of expected node script extensions (#1449)John Geebefore adoptiona28a89b
lines 91–104why, one step back91 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-ts']);92 expect(stdout).toBe('found .ts\n');93});9495test('when subcommand suffix is .cjs then lookup succeeds', async() => {96 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');97 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-cjs']);98 expect(stdout).toBe('found .cjs\n');99});100101test('when subcommand suffix is .mjs then lookup succeeds', async() => {102 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');103 const { stdout } = await execFileAsync('node', [binLinkTs, 'try-mjs']);104 expect(stdout).toBe('found .mjs\n');Add parse result test (#1188)John Geebefore adoption733047f
lines 105–107why, one step back105});106107test('when subsubcommand then lookup sub-sub-command', async() => {Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88
line 108why, one step back108 const { stdout } = await execFileAsync('node', [pm, 'cache', 'clear']);Add parse result test (#1188)John Geebefore adoption733047f
lines 109–110why, one step back109 expect(stdout).toBe('cache-clear\n');110});