Skip to content
Myr

command.executableSubcommand.lookup.test.js

This file

Path

tests/command.executableSubcommand.lookup.test.js

105 lines · 3.5 KiB · JavaScript

Last changed by

Merge pull request #1108 from shadowspawn/feature/timeoutTomoaki Abebefore adoption7c22701

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–16why, 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 {15 expect(stderr).toBe('error: pm-list(1) does not exist, try --help\n');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–28why, 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 {27 expect(stderr).toBe('error: pm-list(1) does not exist, try --help\n');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 pull request #1108 from shadowspawn/feature/timeoutTomoaki Abebefore adoption7c22701

line 92why, one step back
92 jest.setTimeout(20000); // Extend timeout for GitHub Actions

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

lines 93–94why, one step back
93 const binLinkTs = path.join(__dirname, 'fixtures-ts', 'pm.ts');
94 childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], function(_error, stdout, stderr) {

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

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

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

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

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

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