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 develop spec #69

Merged
merged 2 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
75 changes: 0 additions & 75 deletions spec/develop-spec.coffee

This file was deleted.

117 changes: 54 additions & 63 deletions spec/develop-spec.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,75 @@
/*
* 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 apm = require('../lib/apm-cli');

describe("apm develop", function() {
let [repoPath, linkedRepoPath] = Array.from([]);
describe('apm develop', () => {
let linkedRepoPath, repoPath;

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

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

const atomReposHome = temp.mkdirSync('apm-repos-home-dir-');
process.env.ATOM_REPOS_HOME = atomReposHome;

repoPath = path.join(atomReposHome, 'fake-package');
return linkedRepoPath = path.join(atomHome, 'dev', 'packages', 'fake-package');
linkedRepoPath = path.join(atomHome, 'dev', 'packages', 'fake-package');
});

describe("when the package doesn't have a published repository url", () => it("logs an error", function() {
const Develop = require('../lib/develop');
spyOn(Develop.prototype, "getRepositoryUrl").andCallFake((packageName, callback) => callback("Here is the error"));

const callback = jasmine.createSpy('callback');
apm.run(['develop', "fake-package"], callback);

waitsFor('waiting for develop to complete', () => callback.callCount === 1);

return runs(function() {
expect(callback.mostRecentCall.args[0]).toBe("Here is the error");
expect(fs.existsSync(repoPath)).toBeFalsy();
return expect(fs.existsSync(linkedRepoPath)).toBeFalsy();
});
}));

describe("when the repository hasn't been cloned", () => it("clones the repository to ATOM_REPOS_HOME and links it to ATOM_HOME/dev/packages", function() {
const Develop = require('../lib/develop');
spyOn(Develop.prototype, "getRepositoryUrl").andCallFake(function(packageName, callback) {
const repoUrl = path.join(__dirname, 'fixtures', 'repo.git');
return callback(null, repoUrl);
describe("when the package doesn't have a published repository url", () => {
it('logs an error', () => {
const Develop = require('../lib/develop');
spyOn(Develop.prototype, 'getRepositoryUrl').andCallFake((packageName, callback) => {
callback('Here is the error');
});
const callback = jasmine.createSpy('callback');
apm.run(['develop', 'fake-package'], callback);
waitsFor('waiting for develop to complete', () => callback.callCount === 1);
runs(() => {
expect(callback.mostRecentCall.args[0]).toBe('Here is the error');
expect(fs.existsSync(repoPath)).toBeFalsy();
expect(fs.existsSync(linkedRepoPath)).toBeFalsy();
});
});
spyOn(Develop.prototype, "installDependencies").andCallFake(function(packageDirectory, options) {
return this.linkPackage(packageDirectory, options);
});

const callback = jasmine.createSpy('callback');
apm.run(['develop', "fake-package"], callback);

waitsFor('waiting for develop to complete', () => callback.callCount === 1);
});

return runs(function() {
expect(callback.mostRecentCall.args[0]).toBeFalsy();
expect(fs.existsSync(repoPath)).toBeTruthy();
expect(fs.existsSync(path.join(repoPath, 'Syntaxes', 'Makefile.plist'))).toBeTruthy();
expect(fs.existsSync(linkedRepoPath)).toBeTruthy();
return expect(fs.realpathSync(linkedRepoPath)).toBe(fs.realpathSync(repoPath));
describe("when the repository hasn't been cloned", () => {
it('clones the repository to ATOM_REPOS_HOME and links it to ATOM_HOME/dev/packages', () => {
const Develop = require('../lib/develop');
spyOn(Develop.prototype, 'getRepositoryUrl').andCallFake((packageName, callback) => {
const repoUrl = path.join(__dirname, 'fixtures', 'repo.git');
callback(null, repoUrl);
});
spyOn(Develop.prototype, 'installDependencies').andCallFake(function (packageDirectory, options) {
this.linkPackage(packageDirectory, options);
});
const callback = jasmine.createSpy('callback');
apm.run(['develop', 'fake-package'], callback);
waitsFor('waiting for develop to complete', () => callback.callCount === 1);
runs(() => {
expect(callback.mostRecentCall.args[0]).toBeFalsy();
expect(fs.existsSync(repoPath)).toBeTruthy();
expect(fs.existsSync(path.join(repoPath, 'Syntaxes', 'Makefile.plist'))).toBeTruthy();
expect(fs.existsSync(linkedRepoPath)).toBeTruthy();
expect(fs.realpathSync(linkedRepoPath)).toBe(fs.realpathSync(repoPath));
});
});
}));

return describe("when the repository has already been cloned", () => it("links it to ATOM_HOME/dev/packages", function() {
fs.makeTreeSync(repoPath);
fs.writeFileSync(path.join(repoPath, "package.json"), "");
const callback = jasmine.createSpy('callback');
apm.run(['develop', "fake-package"], callback);

waitsFor('waiting for develop to complete', () => callback.callCount === 1);
});

return runs(function() {
expect(callback.mostRecentCall.args[0]).toBeFalsy();
expect(fs.existsSync(repoPath)).toBeTruthy();
expect(fs.existsSync(linkedRepoPath)).toBeTruthy();
return expect(fs.realpathSync(linkedRepoPath)).toBe(fs.realpathSync(repoPath));
describe('when the repository has already been cloned', () => {
it('links it to ATOM_HOME/dev/packages', () => {
fs.makeTreeSync(repoPath);
fs.writeFileSync(path.join(repoPath, 'package.json'), '');
const callback = jasmine.createSpy('callback');
apm.run(['develop', 'fake-package'], callback);
waitsFor('waiting for develop to complete', () => callback.callCount === 1);
runs(() => {
expect(callback.mostRecentCall.args[0]).toBeFalsy();
expect(fs.existsSync(repoPath)).toBeTruthy();
expect(fs.existsSync(linkedRepoPath)).toBeTruthy();
expect(fs.realpathSync(linkedRepoPath)).toBe(fs.realpathSync(repoPath));
});
});
}));
});
});
18 changes: 0 additions & 18 deletions spec/spec-helper.coffee

This file was deleted.