@@ -7,40 +7,79 @@ import { generatePackageJson } from '../../../../src/templates/configs/package-j
77
88describe ( 'configs/package-json' , ( ) => {
99 describe ( 'generatePackageJson' , ( ) => {
10- it ( 'should generate valid JSON' , ( ) => {
11- const content = generatePackageJson ( { tarballRelPath : '.apiops/apiops-0.1.0.tgz' } ) ;
12- expect ( ( ) => JSON . parse ( content ) ) . not . toThrow ( ) ;
13- } ) ;
10+ describe ( 'local mode' , ( ) => {
11+ it ( 'should generate valid JSON' , ( ) => {
12+ const content = generatePackageJson ( { mode : 'local' , tarballRelPath : '.apiops/apiops-0.1.0.tgz' } ) ;
13+ expect ( ( ) => JSON . parse ( content ) ) . not . toThrow ( ) ;
14+ } ) ;
1415
15- it ( 'should include file: dependency for the tarball' , ( ) => {
16- const content = generatePackageJson ( { tarballRelPath : '.apiops/apiops-0.1.0.tgz' } ) ;
17- const pkg = JSON . parse ( content ) ;
18- expect ( pkg . dependencies . apiops ) . toBe ( 'file:.apiops/apiops-0.1.0.tgz' ) ;
19- } ) ;
16+ it ( 'should include file: dependency for the tarball' , ( ) => {
17+ const content = generatePackageJson ( { mode : 'local' , tarballRelPath : '.apiops/apiops-0.1.0.tgz' } ) ;
18+ const pkg = JSON . parse ( content ) ;
19+ expect ( pkg . dependencies . apiops ) . toBe ( 'file:.apiops/apiops-0.1.0.tgz' ) ;
20+ } ) ;
2021
21- it ( 'should set private to true' , ( ) => {
22- const content = generatePackageJson ( { tarballRelPath : '.apiops/apiops-0.1.0.tgz' } ) ;
23- const pkg = JSON . parse ( content ) ;
24- expect ( pkg . private ) . toBe ( true ) ;
25- } ) ;
22+ it ( 'should set private to true' , ( ) => {
23+ const content = generatePackageJson ( { mode : 'local' , tarballRelPath : '.apiops/apiops-0.1.0.tgz' } ) ;
24+ const pkg = JSON . parse ( content ) ;
25+ expect ( pkg . private ) . toBe ( true ) ;
26+ } ) ;
2627
27- it ( 'should include name and version' , ( ) => {
28- const content = generatePackageJson ( { tarballRelPath : '.apiops/apiops-0.1.0.tgz' } ) ;
29- const pkg = JSON . parse ( content ) ;
30- expect ( pkg . name ) . toBeTruthy ( ) ;
31- expect ( pkg . version ) . toBeTruthy ( ) ;
32- } ) ;
28+ it ( 'should include name and version' , ( ) => {
29+ const content = generatePackageJson ( { mode : 'local' , tarballRelPath : '.apiops/apiops-0.1.0.tgz' } ) ;
30+ const pkg = JSON . parse ( content ) ;
31+ expect ( pkg . name ) . toBeTruthy ( ) ;
32+ expect ( pkg . version ) . toBeTruthy ( ) ;
33+ } ) ;
34+
35+ it ( 'should use forward slashes in dependency path' , ( ) => {
36+ // Even if path.join produces backslashes on Windows, the output should use /
37+ const content = generatePackageJson ( { mode : 'local' , tarballRelPath : '.apiops\\apiops-0.1.0.tgz' } ) ;
38+ const pkg = JSON . parse ( content ) ;
39+ expect ( pkg . dependencies . apiops ) . toBe ( 'file:.apiops/apiops-0.1.0.tgz' ) ;
40+ } ) ;
3341
34- it ( 'should use forward slashes in dependency path' , ( ) => {
35- // Even if path.join produces backslashes on Windows, the output should use /
36- const content = generatePackageJson ( { tarballRelPath : '.apiops\\apiops-0.1.0.tgz' } ) ;
37- const pkg = JSON . parse ( content ) ;
38- expect ( pkg . dependencies . apiops ) . toBe ( 'file:.apiops/apiops-0.1.0.tgz' ) ;
42+ it ( 'should end with a newline' , ( ) => {
43+ const content = generatePackageJson ( { mode : 'local' , tarballRelPath : '.apiops/apiops-0.1.0.tgz' } ) ;
44+ expect ( content . endsWith ( '\n' ) ) . toBe ( true ) ;
45+ } ) ;
3946 } ) ;
4047
41- it ( 'should end with a newline' , ( ) => {
42- const content = generatePackageJson ( { tarballRelPath : '.apiops/apiops-0.1.0.tgz' } ) ;
43- expect ( content . endsWith ( '\n' ) ) . toBe ( true ) ;
48+ describe ( 'npm mode' , ( ) => {
49+ it ( 'should generate valid JSON' , ( ) => {
50+ const content = generatePackageJson ( { mode : 'npm' } ) ;
51+ expect ( ( ) => JSON . parse ( content ) ) . not . toThrow ( ) ;
52+ } ) ;
53+
54+ it ( 'should include @peterhauge/apiops-cli dependency' , ( ) => {
55+ const content = generatePackageJson ( { mode : 'npm' } ) ;
56+ const pkg = JSON . parse ( content ) ;
57+ expect ( pkg . dependencies [ '@peterhauge/apiops-cli' ] ) . toBe ( 'latest' ) ;
58+ } ) ;
59+
60+ it ( 'should NOT include apiops dependency' , ( ) => {
61+ const content = generatePackageJson ( { mode : 'npm' } ) ;
62+ const pkg = JSON . parse ( content ) ;
63+ expect ( pkg . dependencies . apiops ) . toBeUndefined ( ) ;
64+ } ) ;
65+
66+ it ( 'should set private to true' , ( ) => {
67+ const content = generatePackageJson ( { mode : 'npm' } ) ;
68+ const pkg = JSON . parse ( content ) ;
69+ expect ( pkg . private ) . toBe ( true ) ;
70+ } ) ;
71+
72+ it ( 'should include name and version' , ( ) => {
73+ const content = generatePackageJson ( { mode : 'npm' } ) ;
74+ const pkg = JSON . parse ( content ) ;
75+ expect ( pkg . name ) . toBeTruthy ( ) ;
76+ expect ( pkg . version ) . toBeTruthy ( ) ;
77+ } ) ;
78+
79+ it ( 'should end with a newline' , ( ) => {
80+ const content = generatePackageJson ( { mode : 'npm' } ) ;
81+ expect ( content . endsWith ( '\n' ) ) . toBe ( true ) ;
82+ } ) ;
4483 } ) ;
4584 } ) ;
4685} ) ;
0 commit comments