Skip to content
Myr

command.executableSubcommand.lookup.test.js

This file

Path

tests/command.executableSubcommand.lookup.test.js

92 lines · 3.5 KiB · JavaScript

Last changed by

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

History of this file

Take it

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 1–2why, one step back
1const childProcess = require('child_process');
2const path = require('path');

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 3–4why, one step back
3const util = require('util');
4const execAsync = util.promisify(childProcess.exec);

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

line 5why, one step back
5

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

line 6why, one step back
6// Calling node explicitly so pm works without file suffix cross-platform.

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

line 7why, one step back
7

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 8–10why, one step back
8// Get false positives due to use of testOrSkipOnWindows
9/* eslint-disable jest/no-standalone-expect */10

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

lines 11–13why, one step back
11const testOrSkipOnWindows = (process.platform === 'win32') ? test.skip : test;
12const pm = path.join(__dirname, './fixtures/pm');13

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 14–16why, one step back
14test('when subcommand file missing then error', () => {
15 expect.assertions(1);16 return execAsync(`node ${pm} list`).catch((err) => {

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

line 19why, one step back
19 expect(err.stderr).toBeDefined();

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

line 20why, one step back
20 } else {

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

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

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

line 22why, one step back
22 }

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 23–25why, one step back
23 });
24});25

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 26–28why, one step back
26test('when alias subcommand file missing then error', () => {
27 expect.assertions(1);28 return execAsync(`node ${pm} lst`).catch((err) => {

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

line 31why, one step back
31 expect(err.stderr).toBeDefined();

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

line 32why, one step back
32 } else {

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

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

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

line 34why, one step back
34 }

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 38–40why, one step back
38test('when subcommand file has no suffix then lookup succeeds', async() => {
39 const { stdout } = await execAsync(`node ${pm} install`);40 expect(stdout).toBe('install\n');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 43–45why, one step back
43test('when alias subcommand file has no suffix then lookup succeeds', async() => {
44 const { stdout } = await execAsync(`node ${pm} i`);45 expect(stdout).toBe('install\n');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 48–50why, one step back
48test('when subcommand target executablefile has no suffix then lookup succeeds', async() => {
49 const { stdout } = await execAsync(`node ${pm} specifyInstall`);50 expect(stdout).toBe('install\n');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 53–55why, one step back
53test('when subcommand file suffix .js then lookup succeeds', async() => {
54 const { stdout } = await execAsync(`node ${pm} publish`);55 expect(stdout).toBe('publish\n');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 58–60why, one step back
58test('when alias subcommand file suffix .js then lookup succeeds', async() => {
59 const { stdout } = await execAsync(`node ${pm} p`);60 expect(stdout).toBe('publish\n');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 63–65why, one step back
63test('when subcommand target executablefile has suffix .js then lookup succeeds', async() => {
64 const { stdout } = await execAsync(`node ${pm} specifyPublish`);65 expect(stdout).toBe('publish\n');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

line 68why, one step back
68testOrSkipOnWindows('when subcommand file is symlink then lookup succeeds', async() => {

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

line 69why, one step back
69 const pmlink = path.join(__dirname, 'fixtures', 'pmlink');

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 70–71why, one step back
70 const { stdout } = await execAsync(`node ${pmlink} install`);
71 expect(stdout).toBe('install\n');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 72–73why, one step back
72});
73

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

line 74why, one step back
74testOrSkipOnWindows('when subcommand file is double symlink then lookup succeeds', async() => {

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

line 75why, one step back
75 const pmlink = path.join(__dirname, 'fixtures', 'another-dir', 'pm');

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 76–77why, one step back
76 const { stdout } = await execAsync(`node ${pmlink} install`);
77 expect(stdout).toBe('install\n');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 78–79why, one step back
78});
79

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

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

Merge branch 'develop' into release/5.xJohn Geebefore adoptiondd23b4c

lines 81–82why, one step back
81 // We support looking for ts files for ts-node in particular, but don't need to test ts-node itself.
82 // The program and the subcommand `pm-install.ts` are both plain JavaScript code.

Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf

line 83why, one step back
83 const binLinkTs = path.join(__dirname, 'fixtures-ts', 'pm.ts');

Merge branch 'develop' into release/5.xJohn Geebefore adoptiondd23b4c

line 84why, one step back
84 // childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], function(_error, stdout, stderr) {

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 85–86why, one step back
85 const { stdout } = await execAsync(`node ${binLinkTs} install`);
86 expect(stdout).toBe('install\n');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 87–88why, one step back
87});
88

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 89–91why, one step back
89test('when subsubcommand then lookup sub-sub-command', async() => {
90 const { stdout } = await execAsync(`node ${pm} cache clear`);91 expect(stdout).toBe('cache-clear\n');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

line 92why, one step back
92});