Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .azure-pipelines-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Steps for building and testing commander.js. See jobs defined in .azure-pipelines.yml.
#

steps:
# Clones the repo. This is an explicit step to preserve symlinks for Windows.
- checkout: self

- task: NodeTool@0
inputs:
versionSpec: $(NODE_VERSION)
checkLatest: 'true'
displayName: 'Install Node.js'

# Run npm ci by default unless NPM_INSTALL is set
- script: npm ci
displayName: 'Install dependencies'
condition: not(variables.NPM_INSTALL)

# Otherwise, run npm install if NPM_INSTALL is set (typically for Node versions < 10.x)
- script: npm install
displayName: 'Install dependencies (npm install)'
condition: variables.NPM_INSTALL

- script: npm run lint
displayName: 'Run lint'
condition: variables.LINT

- script: npm run test
displayName: 'Run tests'
condition: not(variables.SKIP_TESTS)
49 changes: 49 additions & 0 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Azure Pipelines configuration for building and testing commander.js on Linux, Windows, and macOS.
#

trigger:
- master

jobs:
- job: Linux
pool:
vmImage: 'ubuntu-16.04'
strategy:
matrix:
Node6:
NODE_VERSION: '6.x'
NPM_INSTALL: true
Node8:
NODE_VERSION: '8.x'
NPM_INSTALL: true
Node10:
NODE_VERSION: '10.x'
Lint:
NODE_VERSION: '10.x'
LINT: true
SKIP_TESTS: true
steps:
- template: .azure-pipelines-steps.yml

- job: Windows
pool:
vmImage: 'vs2017-win2016'
strategy:
matrix:
Node10:
NODE_VERSION: '10.x'
steps:
- script: git config --global core.symlinks true
displayName: 'Preserve symbolic links on check out'
- template: .azure-pipelines-steps.yml

- job: Mac
pool:
vmImage: 'macOS-10.13'
strategy:
matrix:
Node10:
NODE_VERSION: '10.x'
steps:
- template: .azure-pipelines-steps.yml
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


[![Build Status](https://api.travis-ci.org/tj/commander.js.svg?branch=master)](http://travis-ci.org/tj/commander.js)
[![Azure Pipelines Build Status](https://dev.azure.com/commanderjs/commander.js/_apis/build/status/commander.js-CI?branchName=master)](https://dev.azure.com/commanderjs/commander.js/_build/latest?definitionId=1&branchName=master)
[![NPM Version](http://img.shields.io/npm/v/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
[![NPM Downloads](https://img.shields.io/npm/dm/commander.svg?style=flat)](https://npmcharts.com/compare/commander?minimal=true)
[![Install Size](https://packagephobia.now.sh/badge?p=commander)](https://packagephobia.now.sh/result?p=commander)
Expand Down
1 change: 1 addition & 0 deletions Readme_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


[![Build Status](https://api.travis-ci.org/tj/commander.js.svg)](http://travis-ci.org/tj/commander.js)
[![Azure Pipelines Build Status](https://dev.azure.com/commanderjs/commander.js/_apis/build/status/commander.js-CI?branchName=master)](https://dev.azure.com/commanderjs/commander.js/_build/latest?definitionId=1&branchName=master)
[![NPM Version](http://img.shields.io/npm/v/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
[![NPM Downloads](https://img.shields.io/npm/dm/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
[![Join the chat at https://gitter.im/tj/commander.js](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tj/commander.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down
7 changes: 6 additions & 1 deletion test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { spawnSync } = require('child_process')
const { readdirSync } = require('fs')
const { extname, join } = require('path')
const { isSkipped } = require('./utils.js');

process.env.NODE_ENV = 'test';

Expand All @@ -13,7 +14,11 @@ readdirSync(__dirname).forEach((file) => {
process.stdout.write(`\x1b[90m ${file}\x1b[0m `);
const result = spawnSync(process.argv0, [ join('test', file) ]);
if (result.status === 0) {
process.stdout.write('\x1b[36m✓\x1b[0m\n');
if (isSkipped(result.stdout)) {
process.stdout.write('\x1b[33mSKIPPED\x1b[0m\n');
} else {
process.stdout.write('\x1b[36m✓\x1b[0m\n');
}
} else {
process.stdout.write('\x1b[31m✖\x1b[0m\n');
console.error(result.stderr.toString('utf8'));
Expand Down
16 changes: 10 additions & 6 deletions test/test.command.executableSubcommand.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
var exec = require('child_process').exec
, path = require('path')
, should = require('should');
, should = require('should')
, utils = require('./utils.js');



var bin = path.join(__dirname, './fixtures/pm')
var bin = 'node ' + path.join(__dirname, './fixtures/pm')
// not exist
exec(bin + ' list', function (error, stdout, stderr) {
//stderr.should.equal('\n pm-list(1) does not exist, try --help\n\n');
Expand All @@ -25,11 +24,16 @@ exec(bin + ' publish', function (error, stdout, stderr) {
// spawn EACCES
exec(bin + ' search', function (error, stdout, stderr) {
// TODO error info are not the same in between <v0.10 and v0.12
should.notEqual(0, stderr.length);
// search command works on windows
if (utils.isWindows()) {
stdout.should.equal('search\n');
} else {
should.notEqual(0, stderr.length);
}
});

// when `bin` is a symbol link for mocking global install
var bin = path.join(__dirname, './fixtures/pmlink')
var bin = 'node ' + path.join(__dirname, './fixtures/pmlink')
// success case
exec(bin + ' install', function (error, stdout, stderr) {
stdout.should.equal('install\n');
Expand Down
9 changes: 8 additions & 1 deletion test/test.command.executableSubcommand.signals.hup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
var spawn = require('child_process').spawn,
path = require('path'),
should = require('should');
should = require('should'),
utils = require('./utils.js');

// Skip this test for Windows since signals are unsupported
if (utils.isWindows()) {
utils.skip();
return;
}

var bin = path.join(__dirname, './fixtures/pm');
var proc = spawn(bin, ['listen'], {});
Expand Down
9 changes: 8 additions & 1 deletion test/test.command.executableSubcommand.signals.int.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
var spawn = require('child_process').spawn,
path = require('path'),
should = require('should');
should = require('should'),
utils = require('./utils.js');

// Skip this test for Windows since signals are unsupported
if (utils.isWindows()) {
utils.skip();
return;
}

var bin = path.join(__dirname, './fixtures/pm');
var proc = spawn(bin, ['listen'], {});
Expand Down
9 changes: 8 additions & 1 deletion test/test.command.executableSubcommand.signals.term.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
var spawn = require('child_process').spawn,
path = require('path'),
should = require('should');
should = require('should'),
utils = require('./utils.js');

// Skip this test for Windows since signals are unsupported
if (utils.isWindows()) {
utils.skip();
return;
}

var bin = path.join(__dirname, './fixtures/pm');
var proc = spawn(bin, ['listen'], {});
Expand Down
9 changes: 8 additions & 1 deletion test/test.command.executableSubcommand.signals.usr1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
var spawn = require('child_process').spawn,
path = require('path'),
should = require('should');
should = require('should'),
utils = require('./utils.js');

// Skip this test for Windows since signals are unsupported
if (utils.isWindows()) {
utils.skip();
return;
}

var bin = path.join(__dirname, './fixtures/pm');
var proc = spawn(bin, ['listen'], {});
Expand Down
9 changes: 8 additions & 1 deletion test/test.command.executableSubcommand.signals.usr2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
var spawn = require('child_process').spawn,
path = require('path'),
should = require('should');
should = require('should'),
utils = require('./utils.js');

// Skip this test for Windows since signals are unsupported
if (utils.isWindows()) {
utils.skip();
return;
}

var bin = path.join(__dirname, './fixtures/pm');
var proc = spawn(bin, ['listen'], {});
Expand Down
2 changes: 1 addition & 1 deletion test/test.command.executableSubcommandAlias.help.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var exec = require('child_process').exec



var bin = path.join(__dirname, './fixtures/pm')
var bin = 'node ' + path.join(__dirname, './fixtures/pm')

// success case
exec(bin + ' help', function (error, stdout, stderr) {
Expand Down
14 changes: 10 additions & 4 deletions test/test.command.executableSubcommandAlias.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var exec = require('child_process').exec
, path = require('path')
, should = require('should');
, should = require('should')
, utils = require('./utils.js');

var bin = path.join(__dirname, './fixtures/pm')
var bin = 'node ' + path.join(__dirname, './fixtures/pm')

// success case
exec(bin + ' i', function (error, stdout, stderr) {
Expand All @@ -17,11 +18,16 @@ exec(bin + ' p', function (error, stdout, stderr) {
// spawn EACCES
exec(bin + ' s', function (error, stdout, stderr) {
// error info are not the same in between <v0.10 and v0.12
should.notEqual(0, stderr.length);
// search command works on windows
if (utils.isWindows()) {
stdout.should.equal('search\n');
} else {
should.notEqual(0, stderr.length);
}
});

// when `bin` is a symbol link for mocking global install
var bin = path.join(__dirname, './fixtures/pmlink')
var bin = 'node ' + path.join(__dirname, './fixtures/pmlink')
// success case
exec(bin + ' i', function (error, stdout, stderr) {
stdout.should.equal('install\n');
Expand Down
14 changes: 10 additions & 4 deletions test/test.command.executableSubcommandDefault.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
var exec = require('child_process').exec
, path = require('path')
, should = require('should');
, should = require('should')
, utils = require('./utils.js');



var bin = path.join(__dirname, './fixtures/pm')
var bin = 'node ' + path.join(__dirname, './fixtures/pm')
// success case
exec(bin + ' default', function(error, stdout, stderr) {
stdout.should.equal('default\n');
Expand Down Expand Up @@ -35,11 +36,16 @@ exec(bin + ' publish', function (error, stdout, stderr) {
// spawn EACCES
exec(bin + ' search', function (error, stdout, stderr) {
// TODO error info are not the same in between <v0.10 and v0.12
should.notEqual(0, stderr.length);
// search command works on windows
if (utils.isWindows()) {
stdout.should.equal('search\n');
} else {
should.notEqual(0, stderr.length);
}
});

// when `bin` is a symbol link for mocking global install
var bin = path.join(__dirname, './fixtures/pmlink')
var bin = 'node ' + path.join(__dirname, './fixtures/pmlink')
// success case
exec(bin + ' install', function (error, stdout, stderr) {
stdout.should.equal('install\n');
Expand Down
2 changes: 1 addition & 1 deletion test/test.command.executableSubcommandSubCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var exec = require('child_process').exec
* pm cache validate (default)
*/

var bin = path.join(__dirname, './fixtures/pm')
var bin = 'node ' + path.join(__dirname, './fixtures/pm')
// should list commands at top-level sub command
exec(bin + ' cache help', function (error, stdout, stderr) {
stdout.should.containEql('Usage:');
Expand Down
14 changes: 14 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

const SKIPPED_MESSAGE = '**SKIPPED**';

exports.isWindows = function() {
return process.platform == 'win32';
}

exports.skip = function() {
process.stdout.write(SKIPPED_MESSAGE);
}

exports.isSkipped = function(stdout) {
return stdout.indexOf(SKIPPED_MESSAGE) == 0;
}