command.executableSubcommand.lookup.test.js
This file
Path
tests/command.executableSubcommand.lookup.test.js
107 lines · 3.7 KiB · JavaScript
Last changed by
Merge branch 'develop' into release/5.xJohn Geebefore adoptiondd23b4c
History of this fileTake it
Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 1–3why, one step back1const childProcess = require('child_process');2const path = require('path');3Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf
line 4why, one step back4// 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 back5Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf
lines 6–8why, one step back6const testOrSkipOnWindows = (process.platform === 'win32') ? test.skip : test;7const pm = path.join(__dirname, './fixtures/pm');8Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
line 9why, one step back9test('when subcommand file missing then error', (done) => {Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf
lines 10–16why, one step back10 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 back17 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 back22 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 back29 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 back34 childProcess.exec(`node ${pm} install`, function(_error, stdout, stderr) {Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 35–40why, one step back35 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 back41 childProcess.exec(`node ${pm} i`, function(_error, stdout, stderr) {Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 42–47why, one step back42 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 back48 childProcess.exec(`node ${pm} specifyInstall`, function(_error, stdout, stderr) {Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 49–54why, one step back49 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 back55 childProcess.exec(`node ${pm} publish`, function(_error, stdout, stderr) {Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 56–61why, one step back56 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 back62 childProcess.exec(`node ${pm} p`, function(_error, stdout, stderr) {Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 63–68why, one step back63 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 back69 childProcess.exec(`node ${pm} specifyPublish`, function(_error, stdout, stderr) {Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 70–74why, one step back70 expect(stdout).toBe('publish\n');71 done();72 });73});74Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf
lines 75–77why, one step back75testOrSkipOnWindows('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 back78 expect(stdout).toBe('install\n');79 done();80 });81});82Windows tests (and GitHub Actions) (#1070)John Geebefore adoption7ab5fbf
lines 83–85why, one step back83testOrSkipOnWindows('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 back86 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 back92 // 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 back94 const binLinkTs = path.join(__dirname, 'fixtures-ts', 'pm.ts');Merge branch 'develop' into release/5.xJohn Geebefore adoptiondd23b4c
lines 95–96why, one step back95 // 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 back97 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 back103 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 back104 expect(stdout).toBe('cache-clear\n');105 done();106 });107});