Skip to content
Myr

command.executableSubcommand.lookup.test.js

This file

Path

tests/command.executableSubcommand.lookup.test.js

107 lines · 3.7 KiB · JavaScript

Last changed by

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

History of this file

Take it

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

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

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

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

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

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

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

line 9why, one step back
9test('when subcommand file missing then error', (done) => {

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

lines 10–14why, one step back
10 childProcess.exec(`node ${pm} list`, function(_error, stdout, stderr) {
11 if (process.platform === 'win32') {12 // Get uncaught thrown error on Windows13 expect(stderr.length).toBeGreaterThan(0);14 } else {

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

line 15why, one step back
15 expect(stderr).toBe('error: pm-list(1) does not exist\n');

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

line 16why, one step back
16 }

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

lines 17–21why, one step back
17 done();
18 });19});2021test('when alias subcommand file missing then error', (done) => {

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

lines 22–26why, one step back
22 childProcess.exec(`node ${pm} lst`, function(_error, stdout, stderr) {
23 if (process.platform === 'win32') {24 // Get uncaught thrown error on Windows25 expect(stderr.length).toBeGreaterThan(0);26 } else {

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

line 27why, one step back
27 expect(stderr).toBe('error: pm-list(1) does not exist\n');

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

line 28why, one step back
28 }

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

lines 29–33why, one step back
29 done();
30 });31});3233test('when subcommand file has no suffix then lookup succeeds', (done) => {

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

line 34why, one step back
34 childProcess.exec(`node ${pm} install`, function(_error, stdout, stderr) {

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

lines 35–40why, one step back
35 expect(stdout).toBe('install\n');
36 done();37 });38});3940test('when alias subcommand file has no suffix then lookup succeeds', (done) => {

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

line 41why, one step back
41 childProcess.exec(`node ${pm} i`, function(_error, stdout, stderr) {

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

lines 42–47why, one step back
42 expect(stdout).toBe('install\n');
43 done();44 });45});4647test('when subcommand target executablefile has no suffix then lookup succeeds', (done) => {

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

line 48why, one step back
48 childProcess.exec(`node ${pm} specifyInstall`, function(_error, stdout, stderr) {

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

lines 49–54why, one step back
49 expect(stdout).toBe('install\n');
50 done();51 });52});5354test('when subcommand file suffix .js then lookup succeeds', (done) => {

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

line 55why, one step back
55 childProcess.exec(`node ${pm} publish`, function(_error, stdout, stderr) {

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

lines 56–61why, one step back
56 expect(stdout).toBe('publish\n');
57 done();58 });59});6061test('when alias subcommand file suffix .js then lookup succeeds', (done) => {

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

line 62why, one step back
62 childProcess.exec(`node ${pm} p`, function(_error, stdout, stderr) {

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

lines 63–68why, one step back
63 expect(stdout).toBe('publish\n');
64 done();65 });66});6768test('when subcommand target executablefile has suffix .js then lookup succeeds', (done) => {

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

line 69why, one step back
69 childProcess.exec(`node ${pm} specifyPublish`, function(_error, stdout, stderr) {

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

lines 70–74why, one step back
70 expect(stdout).toBe('publish\n');
71 done();72 });73});74

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

lines 75–77why, one step back
75testOrSkipOnWindows('when subcommand file is symlink then lookup succeeds', (done) => {
76 const pmlink = path.join(__dirname, 'fixtures', 'pmlink');77 childProcess.exec(`node ${pmlink} install`, function(_error, stdout, stderr) {

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

lines 78–82why, one step back
78 expect(stdout).toBe('install\n');
79 done();80 });81});82

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

lines 83–85why, one step back
83testOrSkipOnWindows('when subcommand file is double symlink then lookup succeeds', (done) => {
84 const pmlink = path.join(__dirname, 'fixtures', 'another-dir', 'pm');85 childProcess.exec(`node ${pmlink} install`, function(_error, stdout, stderr) {

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

lines 86–91why, one step back
86 expect(stdout).toBe('install\n');
87 done();88 });89});9091test('when subcommand suffix is .ts then lookup succeeds', (done) => {

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

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

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

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

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

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

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

lines 97–102why, one step back
97 expect(stdout).toBe('install\n');
98 done();99 });100});101102test('when subsubcommand then lookup sub-sub-command', (done) => {

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

line 103why, one step back
103 childProcess.exec(`node ${pm} cache clear`, function(_error, stdout, stderr) {

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

lines 104–107why, one step back
104 expect(stdout).toBe('cache-clear\n');
105 done();106 });107});