command.executableSubcommand.lookup.test.js
This file
Path
tests/command.executableSubcommand.lookup.test.js
103 lines · 3.6 KiB · JavaScript
Last changed by
Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
History of this fileTake it
Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 1–103why, one step back1const childProcess = require('child_process');2const path = require('path');34const bin = path.join(__dirname, './fixtures/pm');56test('when subcommand file missing then error', (done) => {7 childProcess.execFile(bin, ['list'], function(_error, stdout, stderr) {8 expect(stderr).toBe('error: pm-list(1) does not exist, try --help\n');9 done();10 });11});1213test('when alias subcommand file missing then error', (done) => {14 childProcess.execFile(bin, ['lst'], function(_error, stdout, stderr) {15 expect(stderr).toBe('error: pm-list(1) does not exist, try --help\n');16 done();17 });18});1920test('when subcommand file has no suffix then lookup succeeds', (done) => {21 childProcess.execFile(bin, ['install'], { }, function(_error, stdout, stderr) {22 expect(stdout).toBe('install\n');23 done();24 });25});2627test('when alias subcommand file has no suffix then lookup succeeds', (done) => {28 childProcess.execFile(bin, ['i'], { }, function(_error, stdout, stderr) {29 expect(stdout).toBe('install\n');30 done();31 });32});3334test('when subcommand target executablefile has no suffix then lookup succeeds', (done) => {35 childProcess.execFile(bin, ['specifyInstall'], { }, function(_error, stdout, stderr) {36 expect(stdout).toBe('install\n');37 done();38 });39});4041test('when subcommand file suffix .js then lookup succeeds', (done) => {42 childProcess.execFile(bin, ['publish'], { }, function(_error, stdout, stderr) {43 expect(stdout).toBe('publish\n');44 done();45 });46});4748test('when alias subcommand file suffix .js then lookup succeeds', (done) => {49 childProcess.execFile(bin, ['p'], { }, function(_error, stdout, stderr) {50 expect(stdout).toBe('publish\n');51 done();52 });53});5455test('when subcommand target executablefile has suffix .js then lookup succeeds', (done) => {56 childProcess.execFile(bin, ['specifyPublish'], { }, function(_error, stdout, stderr) {57 expect(stdout).toBe('publish\n');58 done();59 });60});6162// This is not a behaviour we enforce but rather one that is expected.63test('when subcommand file not executable then error', (done) => {64 childProcess.execFile(bin, ['search'], { }, function(error, stdout, stderr) {65 // In node 8 the EACCES gets thrown instead of emitted through the spawned process.66 // In node 10 and 12 we get the commander error.67 // commander: error: %s(1) not executable. try chmod or run with root68 // node: Error: Command failed: ... Error: spawn EACCES69 expect(error.toString()).toMatch(new RegExp('not executable|EACCES'));70 done();71 });72});7374test('when subcommand file is symlink then lookup succeeds', (done) => {75 const binLink = path.join(__dirname, './fixtures/pmlink');76 childProcess.execFile(binLink, ['install'], { }, function(_error, stdout, stderr) {77 expect(stdout).toBe('install\n');78 done();79 });80});8182test('when subcommand file is double symlink then lookup succeeds', (done) => {83 const binLink = path.join(__dirname, './fixtures/another-dir/pm');84 childProcess.execFile(binLink, ['install'], { }, function(_error, stdout, stderr) {85 expect(stdout).toBe('install\n');86 done();87 });88});8990test('when subcommand suffix is .ts then lookup succeeds', (done) => {91 const binLinkTs = path.join(__dirname, './fixtures-ts/pm.ts');92 childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], { }, function(_error, stdout, stderr) {93 expect(stdout).toBe('install\n');94 done();95 });96});9798test('when subsubcommand then lookup sub-sub-command', (done) => {99 childProcess.execFile(bin, ['cache', 'clear'], { }, function(_error, stdout, stderr) {100 expect(stdout).toBe('cache-clear\n');101 done();102 });103});