Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decaffeinate ci spec #65

Merged
merged 7 commits into from
May 19, 2023
Merged
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
112 changes: 43 additions & 69 deletions spec/ci-spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
const path = require('path');
const fs = require('fs');
const http = require('http');
Expand All @@ -12,133 +6,113 @@ const express = require('express');
const wrench = require('wrench');
const CSON = require('season');
const apm = require('../lib/apm-cli');
const {
nodeVersion
} = require('./config.json');
const { nodeVersion } = JSON.parse(fs.readFileSync(path.join(__dirname,'config.json')));

describe('apm ci', function() {
let [atomHome, resourcePath, server] = Array.from([]);
describe('apm ci', () => {
let server;

beforeEach(function() {
beforeEach(() => {
spyOnToken();
silenceOutput();
process.env.ATOM_HOME = temp.mkdirSync('apm-home-dir-');

atomHome = temp.mkdirSync('apm-home-dir-');
process.env.ATOM_HOME = atomHome;

resourcePath = temp.mkdirSync('atom-resource-path-');
process.env.ATOM_RESOURCE_PATH = resourcePath;

process.env.ATOM_RESOURCE_PATH = temp.mkdirSync('atom-resource-path-');
delete process.env.npm_config_cache;

const app = express();
app.get(`/node/${nodeVersion}/node-${nodeVersion}-headers.tar.gz`, (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'node-dist', `node-${nodeVersion}-headers.tar.gz`)));
app.get(`/node/${nodeVersion}/win-x86/node.lib`, (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'node-dist', 'node.lib')));
app.get(`/node/${nodeVersion}/win-x64/node.lib`, (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'node-dist', 'node_x64.lib')));
app.get(`/node/${nodeVersion}/SHASUMS256.txt`, (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'node-dist', 'SHASUMS256.txt')));
app.get('/test-module-with-dependencies', (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'install-locked-version.json')));
app.get('/test-module', (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'install-test-module.json')));
app.get('/native-module', (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'native-module.json')));
app.get('/tarball/test-module-with-dependencies-1.1.0.tgz', (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'test-module-with-dependencies-1.1.0.tgz')));
app.get('/tarball/test-module-1.1.0.tgz', (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'test-module-1.1.0.tgz')));
app.get('/tarball/native-module-1.0.0.tgz', (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'native-module-1.0.0.tgz')));

app.get(`/node/${nodeVersion}/node-${nodeVersion}-headers.tar.gz`, (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'node-dist', `node-${nodeVersion}-headers.tar.gz`)));
confused-Techie marked this conversation as resolved.
Show resolved Hide resolved
app.get(`/node/${nodeVersion}/win-x86/node.lib`, (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'node-dist', 'node.lib')));
app.get(`/node/${nodeVersion}/win-x64/node.lib`, (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'node-dist', 'node_x64.lib')));
app.get(`/node/${nodeVersion}/SHASUMS256.txt`, (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'node-dist', 'SHASUMS256.txt')));
app.get('/test-module-with-dependencies', (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'install-locked-version.json')));
app.get('/test-module', (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'install-test-module.json')));
app.get('/native-module', (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'native-module.json')));
app.get('/tarball/test-module-with-dependencies-1.1.0.tgz', (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'test-module-with-dependencies-1.1.0.tgz')));
app.get('/tarball/test-module-1.1.0.tgz', (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'test-module-1.1.0.tgz')));
app.get('/tarball/native-module-1.0.0.tgz', (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'native-module-1.0.0.tgz')));
server = http.createServer(app);

let live = false;
server.listen(3000, '127.0.0.1', function() {
process.env.ATOM_ELECTRON_URL = "http://localhost:3000/node";
process.env.ATOM_PACKAGES_URL = "http://localhost:3000/packages";
server.listen(3000, '127.0.0.1', () => {
process.env.ATOM_ELECTRON_URL = 'http://localhost:3000/node';
process.env.ATOM_PACKAGES_URL = 'http://localhost:3000/packages';
process.env.ATOM_ELECTRON_VERSION = nodeVersion;
process.env.npm_config_registry = 'http://localhost:3000/';
return live = true;
live = true;
});
return waitsFor(() => live);
});
waitsFor(() => live);
})

afterEach(function() {
afterEach(() => {
let done = false;
server.close(() => done = true);
return waitsFor(() => done);
server.close(() => {
done = true;
});
waitsFor(() => done);
});

it('installs dependency versions as specified by the lockfile', function() {
it('installs dependency versions as specified by the lockfile', () => {
const moduleDirectory = path.join(temp.mkdirSync('apm-test-'), 'test-module-with-lockfile');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module-with-lockfile'), moduleDirectory);
process.chdir(moduleDirectory);

const callback = jasmine.createSpy('callback');
apm.run(['ci'], callback);
waitsFor('waiting for install to complete', 600000, () => callback.callCount > 0);

return runs(function() {
runs(() => {
expect(callback.mostRecentCall.args[0]).toBeNull();

const pjson0 = CSON.readFileSync(path.join('node_modules', 'test-module-with-dependencies', 'package.json'));
expect(pjson0.version).toBe('1.1.0');

const pjson1 = CSON.readFileSync(path.join('node_modules', 'test-module', 'package.json'));
return expect(pjson1.version).toBe('1.1.0');
expect(pjson1.version).toBe('1.1.0');
});
});

it('builds a native dependency correctly', function() {
it('builds a native dependency correctly', () => {
const moduleDirectory = path.join(temp.mkdirSync('apm-test-'), 'test-module-with-native');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module-with-lockfile'), moduleDirectory);
process.chdir(moduleDirectory);

const pjsonPath = path.join(moduleDirectory, 'package.json');
const pjson = CSON.readFileSync(pjsonPath);
pjson.dependencies['native-module'] = '^1.0.0';
CSON.writeFileSync(pjsonPath, pjson);

const callback0 = jasmine.createSpy('callback');
const callback1 = jasmine.createSpy('callback');

apm.run(['install'], callback0);
waitsFor('waiting for install to complete', 600000, () => callback0.callCount > 0);

runs(function() {
runs(() => {
expect(callback0.mostRecentCall.args[0]).toBeNull();
return apm.run(['ci'], callback1);
apm.run(['ci'], callback1);
});

waitsFor('waiting for ci to complete', 600000, () => callback1.callCount > 0);

return runs(function() {
runs(() => {
expect(callback1.mostRecentCall.args[0]).toBeNull();
return expect(fs.existsSync(
path.join(moduleDirectory, 'node_modules', 'native-module', 'build', 'Release', 'native.node')
)).toBeTruthy();
expect(fs.existsSync(path.join(moduleDirectory, 'node_modules', 'native-module', 'build', 'Release', 'native.node'))).toBeTruthy();
});
});

it('fails if the lockfile is not present', function() {
it('fails if the lockfile is not present', () => {
const moduleDirectory = path.join(temp.mkdirSync('apm-test-'), 'test-module');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module'), moduleDirectory);
process.chdir(moduleDirectory);

const callback = jasmine.createSpy('callback');
apm.run(['ci'], callback);
waitsFor('waiting for install to complete', 600000, () => callback.callCount > 0);

return runs(() => expect(callback.mostRecentCall.args[0]).not.toBeNull());
runs(() => {
expect(callback.mostRecentCall.args[0]).not.toBeNull();
});
});

return it('fails if the lockfile is out of date', function() {
it('fails if the lockfile is out of date', () => {
const moduleDirectory = path.join(temp.mkdirSync('apm-test-'), 'test-module-with-lockfile');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module-with-lockfile'), moduleDirectory);
process.chdir(moduleDirectory);

const pjsonPath = path.join(moduleDirectory, 'package.json');
const pjson = CSON.readFileSync(pjsonPath);
pjson.dependencies['test-module'] = '^1.2.0';
CSON.writeFileSync(pjsonPath, pjson);

const callback = jasmine.createSpy('callback');
apm.run(['ci'], callback);
waitsFor('waiting for install to complete', 600000, () => callback.callCount > 0);

return runs(() => expect(callback.mostRecentCall.args[0]).not.toBeNull());
runs(() => {
expect(callback.mostRecentCall.args[0]).not.toBeNull();
});
});
});
18 changes: 0 additions & 18 deletions spec/spec-helper.coffee

This file was deleted.