@@ -13,7 +13,21 @@ test("no package.json", async () => {
1313 } ) ;
1414} ) ;
1515
16- test ( "with package.json" , async ( ) => {
16+ test ( "with empty package.json" , async ( ) => {
17+ await temporaryDirectoryTask ( async ( dir ) => {
18+ await fs . writeFile ( join ( dir , "package.json" ) , "{}" ) ;
19+ await expect ( _packageJson ( dir ) ) . resolves . toMatchInlineSnapshot ( `
20+ {
21+ "_id": "@",
22+ "name": "",
23+ "readme": "ERROR: No README data found!",
24+ "version": "",
25+ }
26+ ` ) ;
27+ } ) ;
28+ } ) ;
29+
30+ test ( "with minimal package.json" , async ( ) => {
1731 await temporaryDirectoryTask ( async ( dir ) => {
1832 await fs . writeFile ( join ( dir , "package.json" ) , '{ "name": "foo", "version": "1.0.0" }' ) ;
1933 await expect ( _packageJson ( dir ) ) . resolves . toMatchInlineSnapshot ( `
@@ -26,3 +40,91 @@ test("with package.json", async () => {
2640 ` ) ;
2741 } ) ;
2842} ) ;
43+
44+ test ( "with minimal scoped package.json" , async ( ) => {
45+ await temporaryDirectoryTask ( async ( dir ) => {
46+ await fs . writeFile ( join ( dir , "package.json" ) , '{ "name": "@foo/bar", "version": "1.0.0" }' ) ;
47+ await expect ( _packageJson ( dir ) ) . resolves . toMatchInlineSnapshot ( `
48+ {
49+ "_id": "@foo/bar@1.0.0",
50+ "name": "@foo/bar",
51+ "readme": "ERROR: No README data found!",
52+ "version": "1.0.0",
53+ }
54+ ` ) ;
55+ } ) ;
56+ } ) ;
57+
58+ test ( "with package.json from workdir with npm package" , async ( ) => {
59+ await temporaryDirectoryTask ( async ( dir ) => {
60+ await fs . writeFile ( join ( dir , "package.json" ) , '{ "dependencies": { "foo": "1.0.0" } }' ) ;
61+ await expect ( _packageJson ( dir ) ) . resolves . toMatchInlineSnapshot ( `
62+ {
63+ "_id": "@",
64+ "dependencies": {
65+ "foo": "1.0.0",
66+ },
67+ "name": "",
68+ "readme": "ERROR: No README data found!",
69+ "version": "",
70+ }
71+ ` ) ;
72+ } ) ;
73+ } ) ;
74+
75+ test ( "with package.json from workdir with scoped npm package" , async ( ) => {
76+ await temporaryDirectoryTask ( async ( dir ) => {
77+ await fs . writeFile ( join ( dir , "package.json" ) , '{ "dependencies": { "@foo/bar": "^1.0.0" } }' ) ;
78+ await expect ( _packageJson ( dir ) ) . resolves . toMatchInlineSnapshot ( `
79+ {
80+ "_id": "@",
81+ "dependencies": {
82+ "@foo/bar": "^1.0.0",
83+ },
84+ "name": "",
85+ "readme": "ERROR: No README data found!",
86+ "version": "",
87+ }
88+ ` ) ;
89+ } ) ;
90+ } ) ;
91+
92+ test ( "with package.json from workdir with local package" , async ( ) => {
93+ await temporaryDirectoryTask ( async ( dir ) => {
94+ await fs . writeFile (
95+ join ( dir , "package.json" ) ,
96+ '{ "dependencies": { "foo": "/path/to/tarball.tgz" } }' ,
97+ ) ;
98+ await expect ( _packageJson ( dir ) ) . resolves . toMatchInlineSnapshot ( `
99+ {
100+ "_id": "@",
101+ "dependencies": {
102+ "foo": "/path/to/tarball.tgz",
103+ },
104+ "name": "",
105+ "readme": "ERROR: No README data found!",
106+ "version": "",
107+ }
108+ ` ) ;
109+ } ) ;
110+ } ) ;
111+
112+ test ( "with package.json from workdir with local scoped package" , async ( ) => {
113+ await temporaryDirectoryTask ( async ( dir ) => {
114+ await fs . writeFile (
115+ join ( dir , "package.json" ) ,
116+ '{ "dependencies": { "@foo/bar": "/path/to/tarball.tgz" } }' ,
117+ ) ;
118+ await expect ( _packageJson ( dir ) ) . resolves . toMatchInlineSnapshot ( `
119+ {
120+ "_id": "@",
121+ "dependencies": {
122+ "@foo/bar": "/path/to/tarball.tgz",
123+ },
124+ "name": "",
125+ "readme": "ERROR: No README data found!",
126+ "version": "",
127+ }
128+ ` ) ;
129+ } ) ;
130+ } ) ;
0 commit comments