Skip to content

Commit b82efd1

Browse files
sunnylqmgoogle-labs-jules[bot]coderabbitai[bot]CodeRabbit
authored
🧪 Add test coverage for cross-brand constants logic (#36)
* 🧪 test: add coverage for constants logic Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com> * 🧪 test: add coverage for constants logic Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com> * fix: apply CodeRabbit auto-fixes Fixed 2 file(s) based on 1 unresolved review comment. Co-authored-by: CodeRabbit <noreply@coderabbit.ai> * Update package.json --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
1 parent 97d7a66 commit b82efd1

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

‎tests/constants.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { describe, expect, it } from 'bun:test';
2+
3+
const loadConstantsWithArgv = async (argv1: string) => {
4+
const originalArgv = process.argv;
5+
process.argv = ['node', argv1];
6+
try {
7+
const url = `../src/utils/constants.ts?t=${Date.now()}_${Math.random()}`;
8+
const mod = await import(url);
9+
return mod;
10+
} finally {
11+
process.argv = originalArgv;
12+
}
13+
};
14+
15+
describe('constants', () => {
16+
it('should initialize correctly when script is cresc', async () => {
17+
const mod = await loadConstantsWithArgv('/usr/local/bin/cresc');
18+
expect(mod.scriptName).toBe('cresc');
19+
expect(mod.IS_CRESC).toBe(true);
20+
expect(mod.credentialFile).toBe('.cresc.token');
21+
expect(mod.updateJson).toBe('cresc.config.json');
22+
expect(mod.tempDir).toBe('.cresc.temp');
23+
expect(mod.pricingPageUrl).toBe('https://cresc.dev/pricing');
24+
expect(mod.defaultEndpoints).toEqual([
25+
'https://api.cresc.dev',
26+
'https://api.cresc.app',
27+
]);
28+
});
29+
30+
it('should initialize correctly when script is pushy', async () => {
31+
const mod = await loadConstantsWithArgv('/usr/local/bin/pushy');
32+
expect(mod.scriptName).toBe('pushy');
33+
expect(mod.IS_CRESC).toBe(false);
34+
expect(mod.credentialFile).toBe('.update');
35+
expect(mod.updateJson).toBe('update.json');
36+
expect(mod.tempDir).toBe('.pushy');
37+
expect(mod.pricingPageUrl).toBe(
38+
'https://pushy.reactnative.cn/pricing.html',
39+
);
40+
expect(mod.defaultEndpoints).toEqual([
41+
'https://update.reactnative.cn/api',
42+
'https://update.react-native.cn/api',
43+
]);
44+
});
45+
46+
it('should identify PPK bundle file names correctly', async () => {
47+
const { isPPKBundleFileName } = await import('../src/utils/constants.ts');
48+
expect(isPPKBundleFileName('index.bundlejs')).toBe(true);
49+
expect(isPPKBundleFileName('bundle.harmony.js')).toBe(true);
50+
expect(isPPKBundleFileName('index.js')).toBe(false);
51+
expect(isPPKBundleFileName('main.bundlejs')).toBe(false);
52+
});
53+
});

0 commit comments

Comments
 (0)