Skip to content

Commit 8e5787b

Browse files
appdengrabbou
authored andcommitted
Fix for prelink/postlink commands not being called (#65)
The promisify helper went too deep with the arrow functions. Added a test to ensure these commands are called in the right order. Fixes #64
1 parent 63b016f commit 8e5787b

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ log.heading = 'rnpm-link';
1616
const commandStub = (cb) => cb();
1717
const dedupeAssets = (assets) => uniq(assets, asset => path.basename(asset));
1818

19-
const promisify = (func) => () => new Promise((resolve, reject) =>
19+
const promisify = (func) => new Promise((resolve, reject) =>
2020
func((err, res) => err ? reject(err) : resolve(res))
2121
);
2222

test/link.spec.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('link', () => {
6262
});
6363
});
6464

65-
it('should register native module when android/ios projects are present', () => {
65+
it('should register native module when android/ios projects are present', (done) => {
6666
const registerNativeModule = sinon.stub();
6767
const config = {
6868
getProjectConfig: () => ({ android: {}, ios: {}, assets: [] }),
@@ -83,6 +83,33 @@ describe('link', () => {
8383

8484
link(config, ['react-native-blur']).then(() => {
8585
expect(registerNativeModule.calledTwice).to.be.true;
86+
done();
87+
});
88+
});
89+
90+
it('should run prelink and postlink commands at the appropriate times', (done) => {
91+
const registerNativeModule = sinon.stub();
92+
const prelink = sinon.stub().yieldsAsync();
93+
const postlink = sinon.stub().yieldsAsync();
94+
95+
mock(
96+
'../src/ios/registerNativeModule.js',
97+
registerNativeModule
98+
);
99+
100+
const config = {
101+
getProjectConfig: () => ({ ios: {}, assets: [] }),
102+
getDependencyConfig: sinon.stub().returns({
103+
ios: {}, assets: [], commands: { prelink, postlink },
104+
}),
105+
};
106+
107+
const link = require('../src/link');
108+
109+
link(config, ['react-native-blur']).then(() => {
110+
expect(prelink.calledBefore(registerNativeModule)).to.be.true;
111+
expect(postlink.calledAfter(registerNativeModule)).to.be.true;
112+
done();
86113
});
87114
});
88115

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy