Skip to content

Commit

Permalink
Merge pull request #95 from 2colours/asyncify-without-top
Browse files Browse the repository at this point in the history
Asyncify without topmost interface
  • Loading branch information
DeeDeeG authored Nov 12, 2023
2 parents 03b81ad + 4d0b679 commit 13fb284
Show file tree
Hide file tree
Showing 47 changed files with 1,914 additions and 2,053 deletions.
6 changes: 3 additions & 3 deletions spec/ci-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('apm ci', () => {
apm.run(['ci'], callback);
waitsFor('waiting for install to complete', 600000, () => callback.callCount > 0);
runs(() => {
expect(callback.mostRecentCall.args[0]).toBeNull();
expect(callback.mostRecentCall.args[0]).toBeUndefined();
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'));
Expand All @@ -78,12 +78,12 @@ describe('apm ci', () => {
apm.run(['install'], callback0);
waitsFor('waiting for install to complete', 600000, () => callback0.callCount > 0);
runs(() => {
expect(callback0.mostRecentCall.args[0]).toBeNull();
expect(callback0.mostRecentCall.args[0]).toBeUndefined();
apm.run(['ci'], callback1);
});
waitsFor('waiting for ci to complete', 600000, () => callback1.callCount > 0);
runs(() => {
expect(callback1.mostRecentCall.args[0]).toBeNull();
expect(callback1.mostRecentCall.args[0]).toBeUndefined();
expect(fs.existsSync(path.join(moduleDirectory, 'node_modules', 'native-module', 'build', 'Release', 'native.node'))).toBeTruthy();
});
});
Expand Down
13 changes: 5 additions & 8 deletions spec/develop-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path');
const fs = require('fs-plus');
const temp = require('temp');
const apm = require('../src/apm-cli');
const Develop = require('../src/develop');

describe('apm develop', () => {
let linkedRepoPath, repoPath;
Expand All @@ -19,10 +20,7 @@ describe('apm develop', () => {

describe("when the package doesn't have a published repository url", () => {
it('logs an error', () => {
const Develop = require('../src/develop');
spyOn(Develop.prototype, 'getRepositoryUrl').andCallFake((packageName, callback) => {
callback('Here is the error');
});
spyOn(Develop.prototype, 'getRepositoryUrl').andCallFake(_packageName => Promise.reject('Here is the error'));
const callback = jasmine.createSpy('callback');
apm.run(['develop', 'fake-package'], callback);
waitsFor('waiting for develop to complete', () => callback.callCount === 1);
Expand All @@ -36,13 +34,12 @@ describe('apm develop', () => {

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('../src/develop');
spyOn(Develop.prototype, 'getRepositoryUrl').andCallFake((packageName, callback) => {
spyOn(Develop.prototype, 'getRepositoryUrl').andCallFake(_packageName => {
const repoUrl = path.join(__dirname, 'fixtures', 'repo.git');
callback(null, repoUrl);
return Promise.resolve(repoUrl);
});
spyOn(Develop.prototype, 'installDependencies').andCallFake(function (packageDirectory, options) {
this.linkPackage(packageDirectory, options);
return this.linkPackage(packageDirectory, options);
});
const callback = jasmine.createSpy('callback');
apm.run(['develop', 'fake-package'], callback);
Expand Down
26 changes: 13 additions & 13 deletions spec/install-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('apm install', () => {
expect(fs.existsSync(existingTestModuleFile)).toBeFalsy();
expect(fs.existsSync(path.join(testModuleDirectory, 'index.js'))).toBeTruthy();
expect(fs.existsSync(path.join(testModuleDirectory, 'package.json'))).toBeTruthy();
expect(callback.mostRecentCall.args[0]).toBeNull();
expect(callback.mostRecentCall.args[0]).toBeUndefined();
});
});

Expand All @@ -121,7 +121,7 @@ describe('apm install', () => {

runs(() => {
expect(JSON.parse(fs.readFileSync(path.join(packageDirectory, 'package.json'))).version).toBe('1.1.0');
expect(callback.mostRecentCall.args[0]).toBeNull();
expect(callback.mostRecentCall.args[0]).toBeUndefined();
});
});

Expand All @@ -136,7 +136,7 @@ describe('apm install', () => {

runs(() => {
expect(JSON.parse(fs.readFileSync(path.join(packageDirectory, 'package.json'))).version).toBe('1.1.0');
expect(callback.mostRecentCall.args[0]).toBeNull();
expect(callback.mostRecentCall.args[0]).toBeUndefined();
});
});

Expand Down Expand Up @@ -173,7 +173,7 @@ describe('apm install', () => {
expect(fs.existsSync(testModuleDirectory)).toBeTruthy();
expect(fs.existsSync(path.join(testModuleDirectory, 'index.js'))).toBeTruthy();
expect(fs.existsSync(path.join(testModuleDirectory, 'package.json'))).toBeTruthy();
expect(callback.mostRecentCall.args[0]).toBeNull();
expect(callback.mostRecentCall.args[0]).toBeUndefined();
});
});
});
Expand All @@ -195,7 +195,7 @@ describe('apm install', () => {
expect(fs.existsSync(path.join(testModuleDirectory, 'package.json'))).toBeTruthy();
expect(fs.existsSync(path.join(testModule2Directory, 'index2.js'))).toBeTruthy();
expect(fs.existsSync(path.join(testModule2Directory, 'package.json'))).toBeTruthy();
expect(callback.mostRecentCall.args[0]).toBeNull();
expect(callback.mostRecentCall.args[0]).toBeUndefined();
});
});

Expand Down Expand Up @@ -305,7 +305,7 @@ describe('apm install', () => {
expect(fs.existsSync(path.join(testModuleDirectory, 'package.json'))).toBeTruthy();
expect(fs.existsSync(path.join(testModule2Directory, 'index2.js'))).toBeTruthy();
expect(fs.existsSync(path.join(testModule2Directory, 'package.json'))).toBeTruthy();
expect(callback.mostRecentCall.args[0]).toBeNull();
expect(callback.mostRecentCall.args[0]).toBeUndefined();
});
});

Expand Down Expand Up @@ -424,18 +424,17 @@ describe('apm install', () => {
beforeEach(() => {
install = new Install();

const fakeCloneRepository = (url, ...args) => {
const callback = args[args.length - 1];
const fakeCloneRepository = async (url, ..._rest) => {
if (url !== urls[2]) {
callback(new Error('Failed to clone'));
throw new Error('Failed to clone');
}
};

spyOn(install, 'cloneNormalizedUrl').andCallFake(fakeCloneRepository);
});

it('tries cloning the next URL until one works', () => {
install.cloneFirstValidGitUrl(urls, {}, () => {});
it('tries cloning the next URL until one works', async () => {
await install.cloneFirstValidGitUrl(urls, {}, () => {});
expect(install.cloneNormalizedUrl.calls.length).toBe(3);
expect(install.cloneNormalizedUrl.argsForCall[0][0]).toBe(urls[0]);
expect(install.cloneNormalizedUrl.argsForCall[1][0]).toBe(urls[1]);
Expand Down Expand Up @@ -565,7 +564,7 @@ describe('apm install', () => {
});
});

describe('when installing a registred package and --json is specified', () => {
describe('when installing a registered package and --json is specified', () => {
beforeEach(() => {
const callback = jasmine.createSpy('callback');
apm.run(['install', 'test-module', 'test-module2', '--json'], callback);
Expand Down Expand Up @@ -609,7 +608,7 @@ describe('apm install', () => {

waitsFor('waiting for install to complete', 600000, () => callback.callCount === 1);
runs(() => {
expect(callback.mostRecentCall.args[0]).toBeNull();
expect(callback.mostRecentCall.args[0]).toBeUndefined();

const testModuleDirectory = path.join(atomHome, 'packages', 'native-package');
expect(fs.existsSync(path.join(testModuleDirectory, 'index.js'))).toBeTruthy();
Expand All @@ -624,5 +623,6 @@ describe('apm install', () => {
});
});
});

});
});
2 changes: 1 addition & 1 deletion spec/spec-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ global.silenceOutput = (callThrough = false) => {
}
};

global.spyOnToken = () => spyOn(auth, 'getToken').andCallFake(callback => callback(null, 'token'));
global.spyOnToken = () => spyOn(auth, 'getToken').andCallFake(() => Promise.resolve('token'));
2 changes: 1 addition & 1 deletion spec/stars-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('apm stars', () => {

waitsFor('waiting for command to complete', () => callback.callCount > 0);
runs(() => {
expect(callback.mostRecentCall.args[0]).toBeNull();
expect(callback.mostRecentCall.args[0]).toBeUndefined();
expect(fs.existsSync(path.join(testModuleDirectory, 'index.js'))).toBeTruthy();
expect(fs.existsSync(path.join(testModuleDirectory, 'package.json'))).toBeTruthy();
});
Expand Down
1 change: 1 addition & 0 deletions spec/test-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('apm test', () => {
removeListener() {}
}); // no op
apm.run(['test'], callback);
waitsFor('waiting for command to complete', () => callback.callCount > 0);
};

describe('successfully', () => {
Expand Down
10 changes: 2 additions & 8 deletions spec/unpublish-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ describe('apm unpublish', () => {
describe('when the user accepts the default answer', () => {
it('does not unpublish the package', () => {
const callback = jasmine.createSpy('callback');
spyOn(Unpublish.prototype, 'prompt').andCallFake((...args) => {
const cb = args.pop();
cb('');
});
spyOn(Unpublish.prototype, 'prompt').andCallFake(_question => Promise.resolve(''));
spyOn(Unpublish.prototype, 'unpublishPackage');
apm.run(['unpublish', 'test-package'], callback);

Expand Down Expand Up @@ -129,10 +126,7 @@ describe('apm unpublish', () => {
describe('when the user accepts the default answer', () => {
it('does not unpublish the package', () => {
const callback = jasmine.createSpy('callback');
spyOn(Unpublish.prototype, 'prompt').andCallFake((...args) => {
const cb = args.pop();
cb('');
});
spyOn(Unpublish.prototype, 'prompt').andCallFake(_question => Promise.resolve(''));
spyOn(Unpublish.prototype, 'unpublishPackage');
apm.run(['unpublish', 'test-package'], callback);

Expand Down
Loading

0 comments on commit 13fb284

Please sign in to comment.