11import type * as d from '@stencil/core/declarations' ;
22import { mockBuildCtx , mockCompilerCtx , mockValidatedConfig } from '@stencil/core/testing' ;
3- import { DIST_COLLECTION , DIST_CUSTOM_ELEMENTS } from '@utils' ;
43import path from 'path' ;
54
6- import { normalizePath } from '../../../utils/normalize-path' ;
75import * as v from '../validate-build-package-json' ;
86
97describe ( 'validate-package-json' , ( ) => {
108 let config : d . ValidatedConfig ;
119 let compilerCtx : d . CompilerCtx ;
1210 let buildCtx : d . BuildCtx ;
1311 let collectionOutputTarget : d . OutputTargetDistCollection ;
14- let typesOutputTarget : d . OutputTargetDistTypes ;
1512 const root = path . resolve ( '/' ) ;
1613
1714 beforeEach ( async ( ) => {
@@ -20,11 +17,6 @@ describe('validate-package-json', () => {
2017 dir : '/dist' ,
2118 collectionDir : '/dist/collection' ,
2219 } ;
23- typesOutputTarget = {
24- type : 'dist-types' ,
25- dir : '/dist' ,
26- typesDir : '/dist/types' ,
27- } ;
2820
2921 const namespace = 'SomeNamespace' ;
3022 config = mockValidatedConfig ( {
@@ -84,87 +76,6 @@ describe('validate-package-json', () => {
8476 } ) ;
8577 } ) ;
8678
87- describe ( 'module' , ( ) => {
88- it ( 'validate dist module' , async ( ) => {
89- config . outputTargets = [ ] ;
90- compilerCtx . fs . writeFile ( path . join ( root , 'dist' , 'index.js' ) , '' ) ;
91- buildCtx . packageJson . module = 'dist/index.js' ;
92- await v . validateModule ( config , compilerCtx , buildCtx ) ;
93- expect ( buildCtx . diagnostics ) . toHaveLength ( 0 ) ;
94- } ) ;
95-
96- it ( 'validates a valid custom elements module' , async ( ) => {
97- config . outputTargets = [
98- {
99- type : DIST_CUSTOM_ELEMENTS ,
100- dir : path . join ( root , 'dist' , 'components' ) ,
101- } ,
102- ] ;
103- buildCtx . packageJson . module = 'dist/components/index.js' ;
104- await v . validateModule ( config , compilerCtx , buildCtx ) ;
105- expect ( buildCtx . diagnostics ) . toHaveLength ( 0 ) ;
106- } ) ;
107-
108- it ( 'errors on an invalid custom elements module' , async ( ) => {
109- config . outputTargets = [
110- {
111- type : DIST_CUSTOM_ELEMENTS ,
112- dir : path . join ( root , 'dist' , 'components' ) ,
113- } ,
114- ] ;
115- buildCtx . packageJson . module = 'dist/index.js' ;
116- await v . validateModule ( config , compilerCtx , buildCtx ) ;
117- expect ( buildCtx . diagnostics ) . toHaveLength ( 1 ) ;
118- const [ diagnostic ] = buildCtx . diagnostics ;
119- expect ( diagnostic . level ) . toBe ( 'warn' ) ;
120- expect ( diagnostic . messageText ) . toBe (
121- `package.json "module" property is set to "dist/index.js". It's recommended to set the "module" property to: ./dist/components/index.js`
122- ) ;
123- } ) ;
124-
125- it ( 'missing dist module' , async ( ) => {
126- config . outputTargets = [ ] ;
127- await v . validateModule ( config , compilerCtx , buildCtx ) ;
128- expect ( buildCtx . diagnostics ) . toHaveLength ( 1 ) ;
129- const [ diagnostic ] = buildCtx . diagnostics ;
130- expect ( diagnostic . level ) . toBe ( 'warn' ) ;
131- expect ( diagnostic . messageText ) . toBe ( 'package.json "module" property is required when generating a distribution.' ) ;
132- } ) ;
133-
134- it . each < {
135- ot : d . OutputTarget ;
136- path : string ;
137- } > ( [
138- {
139- ot : {
140- type : DIST_CUSTOM_ELEMENTS ,
141- dir : path . join ( root , 'dist' , 'components' ) ,
142- } ,
143- path : 'dist/components/index.js' ,
144- } ,
145- {
146- ot : {
147- type : DIST_COLLECTION ,
148- dir : path . join ( root , 'dist' ) ,
149- collectionDir : 'dist/collection' ,
150- } ,
151- path : 'dist/index.js' ,
152- } ,
153- ] ) ( 'errors on missing module w/ $ot.type, suggests $path' , async ( { ot, path } ) => {
154- config . outputTargets = [ ot ] ;
155- buildCtx . packageJson . module = undefined ;
156- await v . validateModule ( config , compilerCtx , buildCtx ) ;
157- expect ( buildCtx . diagnostics ) . toHaveLength ( 1 ) ;
158- const [ diagnostic ] = buildCtx . diagnostics ;
159- expect ( diagnostic . level ) . toBe ( 'warn' ) ;
160- expect ( diagnostic . messageText ) . toBe (
161- `package.json "module" property is required when generating a distribution. It's recommended to set the "module" property to: ${ normalizePath (
162- path
163- ) } `
164- ) ;
165- } ) ;
166- } ) ;
167-
16879 describe ( 'main' , ( ) => {
16980 it ( 'main cannot be the old loader' , async ( ) => {
17081 compilerCtx . fs . writeFile ( path . join ( root , 'dist' , 'somenamespace.js' ) , '' ) ;
@@ -187,33 +98,6 @@ describe('validate-package-json', () => {
18798 } ) ;
18899 } ) ;
189100
190- describe ( 'types' , ( ) => {
191- it ( 'validate types' , async ( ) => {
192- compilerCtx . fs . writeFile ( path . join ( root , 'dist' , 'types' , 'components.d.ts' ) , '' ) ;
193- buildCtx . packageJson . types = 'dist/types/components.d.ts' ;
194- await v . validateTypes ( config , compilerCtx , buildCtx , typesOutputTarget ) ;
195- expect ( buildCtx . diagnostics ) . toHaveLength ( 0 ) ;
196- } ) ;
197-
198- it ( 'not d.ts file' , async ( ) => {
199- compilerCtx . fs . writeFile ( path . join ( root , 'dist' , 'types' , 'components.d.ts' ) , '' ) ;
200- buildCtx . packageJson . types = 'dist/types/components.ts' ;
201- v . validateTypes ( config , compilerCtx , buildCtx , typesOutputTarget ) ;
202- expect ( buildCtx . diagnostics ) . toHaveLength ( 1 ) ;
203- } ) ;
204-
205- it ( 'missing types file' , async ( ) => {
206- buildCtx . packageJson . types = 'dist/types/components.d.ts' ;
207- await v . validateTypes ( config , compilerCtx , buildCtx , typesOutputTarget ) ;
208- expect ( buildCtx . diagnostics ) . toHaveLength ( 1 ) ;
209- } ) ;
210-
211- it ( 'missing types' , async ( ) => {
212- v . validateTypes ( config , compilerCtx , buildCtx , typesOutputTarget ) ;
213- expect ( buildCtx . diagnostics ) . toHaveLength ( 1 ) ;
214- } ) ;
215- } ) ;
216-
217101 describe ( 'collection' , ( ) => {
218102 it ( 'should error when missing collection property' , async ( ) => {
219103 v . validateCollection ( config , compilerCtx , buildCtx , collectionOutputTarget ) ;
0 commit comments