Skip to content

Commit

Permalink
lib: replace EOL with LF
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung authored and priyank-p committed Dec 4, 2018
1 parent 8ccbf25 commit b4d10ed
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 32 deletions.
10 changes: 4 additions & 6 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const assert = require('assert');
const fs = require('fs');
const { ClientRequest } = require('http');
const { EOL } = require('os');
const util = require('util');
const ghauth = util.promisify(require('ghauth'));
const { getMergedConfig, getNcurcPath } = require('./config');
Expand Down Expand Up @@ -35,7 +34,7 @@ async function tryCreateGitHubToken(githubAuth) {
note: 'node-core-utils CLI tools'
});
} catch (e) {
process.stderr.write(`Could not get token: ${e.message}${EOL}`);
process.stderr.write(`Could not get token: ${e.message}\n`);
process.exit(1);
}
return credentials;
Expand All @@ -46,6 +45,7 @@ function encode(name, token) {
}

// TODO: support jenkins only...or not necessary?
// TODO: make this a class with dependency (CLI) injectable for testing
async function auth(
options = { github: true },
githubAuth = ghauth) {
Expand All @@ -64,8 +64,7 @@ async function auth(
'If this is your first time running this command, ' +
'follow the instructions to create an access token' +
'. If you prefer to create it yourself on Github, ' +
'see https://github.com/nodejs/node-core-utils/blob/master/README.md.' +
EOL);
'see https://github.com/nodejs/node-core-utils/blob/master/README.md.\n');
const credentials = await tryCreateGitHubToken(githubAuth);
username = credentials.user;
token = credentials.token;
Expand All @@ -86,8 +85,7 @@ async function auth(
process.stdout.write(
'Get your Jenkins API token in https://ci.nodejs.org/me/configure ' +
'and run the following command to add it to your ncu config: ' +
'ncu-config --global set jenkins_token TOKEN' +
EOL);
'ncu-config --global set jenkins_token TOKEN\n');
process.exit(1);
};
check(username, jenkins_token);
Expand Down
7 changes: 3 additions & 4 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const ora = require('ora');
const { EOL } = require('os');
const chalk = require('chalk');
const read = require('read');
const inquirer = require('inquirer');
Expand All @@ -10,7 +9,7 @@ const { IGNORE } = require('./run');
const { warning, error, info, success } = require('./figures');

const FIGURE_INDENT = ' ';
const EOL_INDENT = `${EOL}${FIGURE_INDENT}`;
const EOL_INDENT = `\n${FIGURE_INDENT}`;

const SPINNER_STATUS = {
SUCCESS: 'success',
Expand Down Expand Up @@ -90,7 +89,7 @@ class CLI {
}

log(text) {
this.write(text + EOL);
this.write(text + '\n');
}

table(first, second = '', length = 11) {
Expand Down Expand Up @@ -132,7 +131,7 @@ class CLI {
this.log(`${prefix}${error} ${obj.message}`);
this.log(`${obj.stack}`);
if (obj.data) {
this.log(`${JSON.stringify(obj.data, null, 2).replace(/\n/g, EOL)}`);
this.log(`${JSON.stringify(obj.data, null, 2)}`);
}
} else {
this.log(prefix + chalk.bold(`${error} ${obj}`));
Expand Down
3 changes: 1 addition & 2 deletions test/fixtures/run-auth-github.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const { EOL } = require('os');
const assert = require('assert');

async function mockCredentials(options) {
Expand All @@ -18,7 +17,7 @@ async function mockCredentials(options) {
(async function() {
const auth = require('../../lib/auth');
const authParams = await auth({ github: true }, mockCredentials);
process.stdout.write(`${JSON.stringify(authParams)}${EOL}`);
process.stdout.write(`${JSON.stringify(authParams)}\n`);
})().catch(err => {
console.error(err);
process.exit(1);
Expand Down
9 changes: 4 additions & 5 deletions test/unit/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const rimraf = require('rimraf');
const mkdirp = require('mkdirp');
const path = require('path');
const fs = require('fs');
const { EOL } = require('os');
const assert = require('assert');
let testCounter = 0; // for tmp directories

Expand Down Expand Up @@ -68,7 +67,7 @@ describe('auth', async function() {
await runAuthScript(
{},
[FIRST_TIME_MSG],
`Could not get token: Bad credentials${EOL}`, 'run-auth-error'
`Could not get token: Bad credentials\n`, 'run-auth-error'
);
});
});
Expand Down Expand Up @@ -131,9 +130,9 @@ function runAuthScript(

try {
let newlineIndex;
while ((newlineIndex = pendingStdout.indexOf(EOL)) !== -1) {
while ((newlineIndex = pendingStdout.indexOf('\n')) !== -1) {
const line = pendingStdout.substr(0, newlineIndex);
pendingStdout = pendingStdout.substr(newlineIndex + EOL.length);
pendingStdout = pendingStdout.substr(newlineIndex + 1);

onLine(line);
}
Expand Down Expand Up @@ -166,7 +165,7 @@ function runAuthScript(

assert(line.match(expected), `${line} should match ${expected}`);
if (reply !== undefined) {
proc.stdin.write(`${reply}${EOL}`);
proc.stdin.write(`${reply}\n`);
}
if (expect.length === 0) {
proc.stdin.end();
Expand Down
29 changes: 14 additions & 15 deletions test/unit/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict';

const assert = require('assert');
const { EOL } = require('os');

const CLI = require('../../lib/cli');
const LogStream = require('../fixtures/log_stream');
let figures = require('../../lib/figures');

function strip(text) {
// eslint-disable-next-line
return text.replace(/\u001b\[.*?m/g, '').replace(/\r?\n|\r/g, EOL);
return text.replace(/\u001b\[.*?m/g, '');
}

const warning = strip(figures.warning);
Expand Down Expand Up @@ -62,15 +61,15 @@ describe('cli', () => {
describe('log', () => {
it('should write in stream', () => {
cli.log('Getting commits...');
assert.strictEqual(logResult(), `Getting commits...${EOL}`);
assert.strictEqual(logResult(), `Getting commits...\n`);
});
});

describe('table', () => {
it('should print the first element with bold style and padding', () => {
cli.table('Title', 'description');
assert.strictEqual(logResult(),
`Title description${EOL}`);
`Title description\n`);
});
});

Expand All @@ -80,73 +79,73 @@ describe('cli', () => {
assert.strictEqual(
logResult(),
'---------------------------------- Separator' +
' -----------------------------------' + EOL);
' -----------------------------------\n');
});

it('should print a separator line with a custom separator', () => {
cli.separator('PR', 20, '+');
assert.strictEqual(
logResult(),
'++++++++ PR ++++++++' + EOL);
'++++++++ PR ++++++++\n');
});

it('should print a separator line without text', () => {
cli.separator();
assert.strictEqual(
logResult(),
'-------------------------------------------------------' +
'-------------------------' + EOL);
'-------------------------\n');
});
});

describe('ok', () => {
it('should print a success message', () => {
cli.ok('Perfect!');
assert.strictEqual(logResult(), ` ${success} Perfect!${EOL}`);
assert.strictEqual(logResult(), ` ${success} Perfect!\n`);
});

it('should print a success message in a new line if specified', () => {
cli.ok('Perfect!', { newline: true });
assert.strictEqual(logResult(),
`${EOL} ${success} Perfect!${EOL}`);
`\n ${success} Perfect!\n`);
});
});

describe('warn', () => {
it('should print a warning message', () => {
cli.warn('Warning!');
assert.strictEqual(logResult(), ` ${warning} Warning!${EOL}`);
assert.strictEqual(logResult(), ` ${warning} Warning!\n`);
});

it('should print a warning message in a new line if specified', () => {
cli.warn('Warning!', { newline: true });
assert.strictEqual(logResult(),
`${EOL} ${warning} Warning!${EOL}`);
`\n ${warning} Warning!\n`);
});
});

describe('info', () => {
it('should print an info message', () => {
cli.info('Info!');
assert.strictEqual(logResult(), ` ${info} Info!${EOL}`);
assert.strictEqual(logResult(), ` ${info} Info!\n`);
});

it('should print an info message in a new line if specified', () => {
cli.info('Info!', { newline: true });
assert.strictEqual(logResult(), `${EOL} ${info} Info!${EOL}`);
assert.strictEqual(logResult(), `\n ${info} Info!\n`);
});
});

// TODO: `Error` instance test
describe('error', () => {
it('should print an error message', () => {
cli.error('Error!');
assert.strictEqual(logResult(), ` ${error} Error!${EOL}`);
assert.strictEqual(logResult(), ` ${error} Error!\n`);
});

it('should print an error message in a new line if specified', () => {
cli.error('Error!', { newline: true });
assert.strictEqual(logResult(), `${EOL} ${error} Error!${EOL}`);
assert.strictEqual(logResult(), `\n ${error} Error!\n`);
});
});
});
Expand Down

0 comments on commit b4d10ed

Please sign in to comment.