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 clean spec #66

Merged
merged 4 commits into from
May 21, 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
90 changes: 0 additions & 90 deletions spec/clean-spec.coffee

This file was deleted.

70 changes: 28 additions & 42 deletions spec/clean-spec.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,52 @@
/*
* 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-plus');
const temp = require('temp');
const express = require('express');
const http = require('http');
const wrench = require('wrench');
const apm = require('../lib/apm-cli');
const {
nodeVersion
} = require('./config.json');
const { nodeVersion } = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')));

describe('apm clean', function() {
let [moduleDirectory, server] = Array.from([]);
describe('apm clean', () => {
let server, moduleDirectory;

beforeEach(function() {
beforeEach(() => {
silenceOutput();
spyOnToken();

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', (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'install-test-module.json')));
app.get('/tarball/test-module-1.2.0.tgz', (request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'test-module-1.2.0.tgz')));

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', (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'install-test-module.json')));
app.get('/tarball/test-module-1.2.0.tgz', (_request, response) => response.sendFile(path.join(__dirname, 'fixtures', 'test-module-1.2.0.tgz')));
server = http.createServer(app);

let live = false;
server.listen(3000, '127.0.0.1', function() {
console.log("Server started");
const atomHome = temp.mkdirSync('apm-home-dir-');
process.env.ATOM_HOME = atomHome;
process.env.ATOM_ELECTRON_URL = "http://localhost:3000/node";
server.listen(3000, '127.0.0.1', () => {
console.log('Server started');
process.env.ATOM_HOME = temp.mkdirSync('apm-home-dir-');
process.env.ATOM_ELECTRON_URL = 'http://localhost:3000/node';
process.env.ATOM_ELECTRON_VERSION = nodeVersion;
process.env.npm_config_registry = 'http://localhost:3000/';

moduleDirectory = path.join(temp.mkdirSync('apm-test-module-'), 'test-module-with-dependencies');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module-with-dependencies'), moduleDirectory);
process.chdir(moduleDirectory);
return live = true;
live = true;
});
return waitsFor(() => live);
});
waitsFor(() => live);
})

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

it('uninstalls any packages not referenced in the package.json', function() {
it('uninstalls any packages not referenced in the package.json', () => {
const removedPath = path.join(moduleDirectory, 'node_modules', 'will-be-removed');
fs.makeTreeSync(removedPath);
fs.writeFileSync(
Expand All @@ -67,16 +57,14 @@ describe('apm clean', function() {

const callback = jasmine.createSpy('callback');
apm.run(['clean'], callback);

waitsFor('waiting for command to complete', () => callback.callCount > 0);

return runs(function() {
runs(() => {
expect(callback.mostRecentCall.args[0]).toBeUndefined();
return expect(fs.existsSync(removedPath)).toBeFalsy();
expect(fs.existsSync(removedPath)).toBeFalsy();
});
});

return it('uninstalls a scoped package', function() {
it('uninstalls a scoped package', () => {
const removedPath = path.join(moduleDirectory, 'node_modules/@types/atom');
fs.makeTreeSync(removedPath);
fs.writeFileSync(
Expand All @@ -87,12 +75,10 @@ describe('apm clean', function() {

const callback = jasmine.createSpy('callback');
apm.run(['clean'], callback);

waitsFor('waiting for command to complete', () => callback.callCount > 0);

return runs(function() {
runs(() => {
expect(callback.mostRecentCall.args[0]).toBeUndefined();
return expect(fs.existsSync(removedPath)).toBeFalsy();
expect(fs.existsSync(removedPath)).toBeFalsy();
});
});
});
18 changes: 0 additions & 18 deletions spec/spec-helper.coffee

This file was deleted.