Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 2491c76 point at it.

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 1–3why, one step back
1const 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 back
4const execFileAsync = util.promisify(childProcess.execFile);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 5–6why, one step back
5
6// 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 back
7// This file does end-to-end tests actually spawning program.
8// See also command.executableSubcommand.search.test.js

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

line 9why, one step back
9

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

line 10why, one step back
10// Suppress false positive warnings due to use of testOrSkipOnWindows

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 11–17why, one step back
11/* 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 back
18 return execFileAsync('node', [pm, 'list']).catch((err) => {

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 19–20why, one step back
19 if (process.platform === 'win32') {
20 // Get uncaught thrown error on Windows

Merge branch 'develop' into release/7.xJohn Geebefore adoptiond90ef12

line 21why, one step back
21 // eslint-disable-next-line jest/no-conditional-expect

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 22–23why, one step back
22 expect(err.stderr).toBeDefined();
23 } else {

Merge branch 'develop' into release/7.xJohn Geebefore adoptiond90ef12

line 24why, one step back
24 // eslint-disable-next-line jest/no-conditional-expect

Update dependencies in 7.x (#1412)John Geebefore adoption469acc9

line 25why, one step back
25 expect(err.stderr).toMatch(/Error: 'pm-list' does not exist/);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 26–31why, one step back
26 }
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 back
32 return execFileAsync('node', [pm, 'lst']).catch((err) => {

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 33–34why, one step back
33 if (process.platform === 'win32') {
34 // Get uncaught thrown error on Windows

Merge branch 'develop' into release/7.xJohn Geebefore adoptiond90ef12

line 35why, one step back
35 // eslint-disable-next-line jest/no-conditional-expect

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 36–37why, one step back
36 expect(err.stderr).toBeDefined();
37 } else {

Merge branch 'develop' into release/7.xJohn Geebefore adoptiond90ef12

line 38why, one step back
38 // eslint-disable-next-line jest/no-conditional-expect

Update dependencies in 7.x (#1412)John Geebefore adoption469acc9

line 39why, one step back
39 expect(err.stderr).toMatch(/Error: 'pm-list' does not exist/);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 40–44why, one step back
40 }
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 back
45 const { stdout } = await execFileAsync('node', [pm, 'install']);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 46–49why, one step back
46 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 back
50 const { stdout } = await execFileAsync('node', [pm, 'i']);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 51–54why, one step back
51 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 back
55 const { stdout } = await execFileAsync('node', [pm, 'specifyInstall']);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 56–59why, one step back
56 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 back
60 const { stdout } = await execFileAsync('node', [pm, 'publish']);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 61–64why, one step back
61 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 back
65 const { stdout } = await execFileAsync('node', [pm, 'p']);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 66–69why, one step back
66 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 back
70 const { stdout } = await execFileAsync('node', [pm, 'specifyPublish']);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 71–75why, one step back
71 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 back
76 const { stdout } = await execFileAsync('node', [pmlink, 'install']);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 77–81why, one step back
77 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 back
82 const { stdout } = await execFileAsync('node', [pmlink, 'install']);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 83–87why, one step back
83 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 back
88 // The subcommand is both plain JavaScript code for this test.
89 const binLinkTs = path.join(__dirname, 'fixtures-extensions', 'pm.js');

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

line 90why, one step back
90 // 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 back
91 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');

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 105–107why, one step back
105});
106107test('when subsubcommand then lookup sub-sub-command', async() => {

Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88

line 108why, one step back
108 const { stdout } = await execFileAsync('node', [pm, 'cache', 'clear']);

URLEncode several chinese toc linkoGsLPbefore adoption2491c76

lines 109–110why, one step back
109 expect(stdout).toBe('cache-clear\n');
110});