Skip to content

Commit

Permalink
Drop Node 6 support. (#66)
Browse files Browse the repository at this point in the history
Drop Node 6 support.
  • Loading branch information
rwjblue committed May 16, 2019
2 parents 0461822 + 3ed2b29 commit 25f7d95
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 94 deletions.
8 changes: 2 additions & 6 deletions .eslintrc.js
Expand Up @@ -2,7 +2,7 @@ module.exports = {
root: true,
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
ecmaVersion: 2018
},
plugins: [
'node',
Expand All @@ -17,11 +17,7 @@ module.exports = {
node: true
},
rules: {
'prettier/prettier': ['error', {
singleQuote: true,
trailingComma: 'es5',
printWidth: 100,
}],
'prettier/prettier': 'error',
},
overrides: [
// test files
Expand Down
5 changes: 5 additions & 0 deletions .prettierrc
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": 'es5',
"printWidth": 100
}
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,6 +1,5 @@
language: node_js
node_js:
- "6"
- "8"
- "10"
- "12"
Expand Down
15 changes: 9 additions & 6 deletions bin/ember-source-channel-url
Expand Up @@ -37,11 +37,12 @@ EXAMPLE:
`);
}

if (['release', 'beta', 'canary'].indexOf(channel) === -1) {
printUsage();
process.exitCode = 1;
} else {
getChannelURL(channel).then(url => {
async function main() {
if (['release', 'beta', 'canary'].indexOf(channel) === -1) {
printUsage();
process.exitCode = 1;
} else {
let url = await getChannelURL(channel);
if (process.stdout.isTTY) {
console.log(
`The URL for the latest tarball from ember-source's ${channel} channel is:\n\n\t${url}\n`
Expand Down Expand Up @@ -85,5 +86,7 @@ if (['release', 'beta', 'canary'].indexOf(channel) === -1) {
process.exitCode = 3;
}
}
});
}
}

main();
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -12,6 +12,7 @@
"bin": "./bin/ember-source-channel-url",
"repository": "git@github.com:rwjblue/ember-source-channel-url.git",
"scripts": {
"lint:js": "eslint .",
"test": "qunit tests/**/*-test.js"
},
"dependencies": {
Expand All @@ -31,6 +32,6 @@
"tmp": "^0.1.0"
},
"engines": {
"node": "6.* || 8.* || >= 10.*"
"node": "8.* || >= 10.*"
}
}
8 changes: 4 additions & 4 deletions src/index.js
@@ -1,11 +1,11 @@
'use strict';
const got = require('got');

module.exports = function(channelType) {
module.exports = async function(channelType) {
let HOST = process.env.EMBER_SOURCE_CHANNEL_URL_HOST || 'https://s3.amazonaws.com';
let PATH = 'builds.emberjs.com';

return got(`${HOST}/${PATH}/${channelType}.json`, { json: true }).then(
result => `${HOST}/${PATH}${result.body.assetPath}`
);
const result = await got(`${HOST}/${PATH}/${channelType}.json`, { json: true });

return `${HOST}/${PATH}${result.body.assetPath}`;
};
2 changes: 1 addition & 1 deletion tests/helpers/server.js
Expand Up @@ -4,7 +4,7 @@ const http = require('http');
const RSVP = require('rsvp');
const getPort = require('get-port');

const host = module.exports.host = 'localhost';
const host = (module.exports.host = 'localhost');

module.exports.createServer = function() {
return getPort().then(port => {
Expand Down
145 changes: 70 additions & 75 deletions tests/index-test.js
Expand Up @@ -18,25 +18,24 @@ QUnit.module('ember-source-channel-url', function(hooks) {
return crypto.randomBytes(Math.ceil(length / 2)).toString('hex');
}

hooks.beforeEach(function() {
hooks.beforeEach(async function() {
let dir = tmp.dirSync();
process.chdir(dir.name);

return createServer().then(server => {
process.env.EMBER_SOURCE_CHANNEL_URL_HOST = `http://localhost:${server.port}`;
let server = await createServer();
process.env.EMBER_SOURCE_CHANNEL_URL_HOST = `http://localhost:${server.port}`;

this.server = server;
this.fakeSHA = randomString(20);
let assetPath = (this.assetPath = `/canary/shas/${this.fakeSHA}.tgz`);
this.server = server;
this.fakeSHA = randomString(20);
let assetPath = (this.assetPath = `/canary/shas/${this.fakeSHA}.tgz`);

this.expectedURL = `http://${server.host}:${server.port}/builds.emberjs.com${this.assetPath}`;
this.expectedURL = `http://${server.host}:${server.port}/builds.emberjs.com${this.assetPath}`;

server.on('/builds.emberjs.com/canary.json', (req, res) => {
res.end(JSON.stringify({ assetPath }));
});

return server.listen(server.port);
server.on('/builds.emberjs.com/canary.json', (req, res) => {
res.end(JSON.stringify({ assetPath }));
});

return server.listen(server.port);
});

hooks.afterEach(function() {
Expand All @@ -45,53 +44,50 @@ QUnit.module('ember-source-channel-url', function(hooks) {
return this.server.close();
});

QUnit.test('works', function(assert) {
QUnit.test('works', async function(assert) {
let expected = `http://${this.server.host}:${this.server.port}/builds.emberjs.com${
this.assetPath
}`;

return getChannelURL('canary').then(actual => {
assert.equal(actual, expected);
});
let actual = await getChannelURL('canary');
assert.equal(actual, expected);
});

QUnit.module('binary', function() {
QUnit.test('works', function(assert) {
return execa(EXECUTABLE_PATH, ['canary']).then(results => {
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');
});
QUnit.test('works', async function(assert) {
let results = await execa(EXECUTABLE_PATH, ['canary']);
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');
});

QUnit.test('when the terminal is not a TTY return only the URL', function(assert) {
QUnit.test('when the terminal is not a TTY return only the URL', async function(assert) {
let file = tmp.fileSync();
return execa(EXECUTABLE_PATH, ['canary'], { stdout: file.fd }).then(() => {
assert.equal(
fs.readFileSync(file.name, { encoding: 'utf8' }),
this.expectedURL,
'stdout is the URL'
);
});
await execa(EXECUTABLE_PATH, ['canary'], { stdout: file.fd });
assert.equal(
fs.readFileSync(file.name, { encoding: 'utf8' }),
this.expectedURL,
'stdout is the URL'
);
});

QUnit.test('updates local package.json when -w is passed (dependencies)', function(assert) {
QUnit.test('updates local package.json when -w is passed (dependencies)', async function(
assert
) {
fs.writeFileSync(
'package.json',
JSON.stringify({ dependencies: { 'ember-source': '^3.10.0' } }),
{ encoding: 'utf8' }
);

return execa(EXECUTABLE_PATH, ['canary', '-w']).then(results => {
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');

assert.deepEqual(JSON.parse(fs.readFileSync('package.json', { encoding: 'utf8' })), {
dependencies: {
'ember-source': this.expectedURL,
},
});
let results = await execa(EXECUTABLE_PATH, ['canary', '-w']);
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');
assert.deepEqual(JSON.parse(fs.readFileSync('package.json', { encoding: 'utf8' })), {
dependencies: {
'ember-source': this.expectedURL,
},
});
});

QUnit.test('updates local package.json when --write is passed (dependencies)', function(
QUnit.test('updates local package.json when --write is passed (dependencies)', async function(
assert
) {
fs.writeFileSync(
Expand All @@ -100,77 +96,76 @@ QUnit.module('ember-source-channel-url', function(hooks) {
{ encoding: 'utf8' }
);

return execa(EXECUTABLE_PATH, ['canary', '--write']).then(results => {
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');

assert.deepEqual(JSON.parse(fs.readFileSync('package.json', { encoding: 'utf8' })), {
dependencies: {
'ember-source': this.expectedURL,
},
});
let results = await execa(EXECUTABLE_PATH, ['canary', '--write']);
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');
assert.deepEqual(JSON.parse(fs.readFileSync('package.json', { encoding: 'utf8' })), {
dependencies: {
'ember-source': this.expectedURL,
},
});
});

QUnit.test('updates local package.json when --write is passed (devDependencies)', function(
assert
) {
fs.writeFileSync(
'package.json',
JSON.stringify({ devDependencies: { 'ember-source': '^3.10.0' } }),
{ encoding: 'utf8' }
);
QUnit.test(
'updates local package.json when --write is passed (devDependencies)',
async function(assert) {
fs.writeFileSync(
'package.json',
JSON.stringify({ devDependencies: { 'ember-source': '^3.10.0' } }),
{ encoding: 'utf8' }
);

return execa(EXECUTABLE_PATH, ['canary', '--write']).then(results => {
let results = await execa(EXECUTABLE_PATH, ['canary', '--write']);
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');

assert.deepEqual(JSON.parse(fs.readFileSync('package.json', { encoding: 'utf8' })), {
devDependencies: {
'ember-source': this.expectedURL,
},
});
});
});
}
);

QUnit.test('preserves line ending when updating package.json', function(assert) {
QUnit.test('preserves line ending when updating package.json', async function(assert) {
fs.writeFileSync(
'package.json',
JSON.stringify({ dependencies: { 'ember-source': '^3.10.0' } }, null, 2) + '\n',
{ encoding: 'utf8' }
);

return execa(EXECUTABLE_PATH, ['canary', '--write']).then(results => {
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');

let expected =
JSON.stringify({ dependencies: { 'ember-source': this.expectedURL } }, null, 2) + '\n';
assert.deepEqual(fs.readFileSync('package.json', { encoding: 'utf8' }), expected);
});
let results = await execa(EXECUTABLE_PATH, ['canary', '--write']);
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');
let expected =
JSON.stringify({ dependencies: { 'ember-source': this.expectedURL } }, null, 2) + '\n';
assert.deepEqual(fs.readFileSync('package.json', { encoding: 'utf8' }), expected);
});

QUnit.test('fails when package.json is missing', function(assert) {
return execa(EXECUTABLE_PATH, ['canary', '--write']).catch(results => {
QUnit.test('fails when package.json is missing', async function(assert) {
try {
await execa(EXECUTABLE_PATH, ['canary', '--write']);
} catch (results) {
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');

assert.ok(
results.stdout.includes('no package.json is available to update'),
'warning is printed indicating -w failed'
);
});
}
});

QUnit.test('fails when ember-source is not a dep', function(assert) {
fs.writeFileSync('package.json', JSON.stringify({}), { encoding: 'utf8' });
QUnit.test('fails when ember-source is not a dep', async function(assert) {
fs.writeFileSync('package.json', JSON.stringify({}), {
encoding: 'utf8',
});

return execa(EXECUTABLE_PATH, ['canary', '--write']).catch(results => {
try {
await execa(EXECUTABLE_PATH, ['canary', '--write']);
} catch (results) {
assert.ok(results.stdout.includes(this.expectedURL), 'URL is present in stdout');

assert.ok(
results.stdout.includes(
'ember-source is not included in dependencies or devDependencies'
),
'warning is printed indicating -w failed'
);
});
}
});
});
});

0 comments on commit 25f7d95

Please sign in to comment.