-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathnpmArgs.test.ts
More file actions
85 lines (70 loc) · 3.56 KB
/
npmArgs.test.ts
File metadata and controls
85 lines (70 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { describe, expect, it } from '@jest/globals';
import { getNpmAuthArgs, getNpmPublishArgs } from '../../packageManager/npmArgs';
import { AuthType } from '../../types/Auth';
import { NpmOptions } from '../../types/NpmOptions';
import { makePackageInfos } from '../../__fixtures__/packageInfos';
describe('getNpmAuthArgs', () => {
type NpmAuthTest = { token?: string; authType?: AuthType; expected: string };
const registry = 'https://testRegistry';
const token = 'someToken';
it.each<NpmAuthTest>([
// no token
{ expected: '' },
// no specified auth type
{ token, expected: '--//testRegistry:_authToken=someToken' },
// different auth types
{ token, authType: 'authtoken', expected: '--//testRegistry:_authToken=someToken' },
{ token, authType: 'password', expected: '--//testRegistry:_password=someToken' },
{ token, authType: 'invalidvalue' as AuthType, expected: '--//testRegistry:_authToken=someToken' },
])('token = $token, authType = $authType', ({ token, authType, expected }) => {
expect(getNpmAuthArgs(registry, token, authType).join(' ')).toStrictEqual(expected);
});
});
describe('getNpmPublishArgs', () => {
const options: NpmOptions = { registry: 'https://testRegistry' };
const packageInfos = makePackageInfos({
basic: {},
tag: { combinedOptions: { tag: 'testTag', defaultNpmTag: 'testDefaultTag' } },
defaultTag: { combinedOptions: { defaultNpmTag: 'testDefaultTag' } },
'@scoped/foo': {},
});
it('uses latest tag if not specified', () => {
const args = getNpmPublishArgs(packageInfos.basic, options).join(' ');
// Test the interesting part separately first, then the whole thing
expect(args).toMatch('--tag latest');
expect(args).toEqual('publish --registry https://testRegistry --tag latest --loglevel warn');
});
it('uses tag if specified', () => {
const args = getNpmPublishArgs(packageInfos.tag, options).join(' ');
expect(args).toMatch('--tag testTag');
});
it('uses defaultNpmTag if tag is not specified', () => {
const args = getNpmPublishArgs(packageInfos.defaultTag, options).join(' ');
expect(args).toMatch('--tag testDefaultTag');
});
it('ignores access for unscoped package', () => {
let args = getNpmPublishArgs(packageInfos.basic, { ...options, access: 'public' }).join(' ');
expect(args).not.toMatch('--access public');
args = getNpmPublishArgs(packageInfos.basic, { ...options, access: 'restricted' }).join(' ');
expect(args).not.toMatch('--access restricted');
});
it('uses specified access for scoped package', () => {
let args = getNpmPublishArgs(packageInfos['@scoped/foo'], { ...options, access: 'public' }).join(' ');
expect(args).toMatch('--access public');
expect(args).toEqual('publish --registry https://testRegistry --tag latest --loglevel warn --access public');
args = getNpmPublishArgs(packageInfos['@scoped/foo'], { ...options, access: 'restricted' }).join(' ');
expect(args).toMatch('--access restricted');
});
it('does not add access for scoped package if not specified', () => {
const args = getNpmPublishArgs(packageInfos['@scoped/foo'], options).join(' ');
expect(args).not.toMatch('--access');
});
it('uses auth args if specified', () => {
const args = getNpmPublishArgs(packageInfos.basic, { ...options, token: 'testToken' }).join(' ');
expect(args).toMatch('--//testRegistry:_authToken=testToken');
});
it('does dry run if specified', () => {
const args = getNpmPublishArgs(packageInfos.basic, { ...options, dryRun: true }).join(' ');
expect(args).toMatch('--dry-run');
});
});