@@ -2,33 +2,18 @@ jest.setTimeout(60000)
22
33const { resolve, join } = require ( 'path' )
44const { readFileSync } = require ( 'fs' )
5- const { Nuxt, Builder, Generator } = require ( 'nuxt-edge' )
6- const request = require ( 'request-promise-native' )
7- const getPort = require ( 'get-port' )
5+ const { setup, generate, loadConfig, get } = require ( '@nuxtjs/module-test-utils' )
86const logger = require ( '../lib/logger' )
97const { createFeed, feedOptions } = require ( './feed-options' )
108
11- const config = require ( './fixture/nuxt.config' )
9+ const config = loadConfig ( __dirname )
1210config . dev = false
1311
14- let nuxt , port
15-
1612logger . mockTypes ( ( ) => jest . fn ( ) )
1713
18- const url = path => `http://localhost:${ port } ${ path } `
19- const get = path => request ( url ( path ) )
20-
21- const setupNuxt = async ( config ) => {
22- const nuxt = new Nuxt ( config )
23- await nuxt . ready ( )
24- await new Builder ( nuxt ) . build ( )
25- port = await getPort ( )
26- await nuxt . listen ( port )
27-
28- return nuxt
29- }
30-
3114describe ( 'module' , ( ) => {
15+ let nuxt
16+
3217 beforeEach ( ( ) => {
3318 logger . clear ( )
3419 } )
@@ -40,50 +25,51 @@ describe('module', () => {
4025 } )
4126
4227 test ( 'generate simple rss' , async ( ) => {
43- nuxt = new Nuxt ( config )
44- await nuxt . ready ( )
45-
46- const builder = new Builder ( nuxt )
47- const generator = new Generator ( nuxt , builder )
48- await generator . generate ( )
28+ ( { nuxt } = await generate ( {
29+ ...config ,
30+ feed : [
31+ { ...createFeed ( ) , ...{ path : '/feed.xml' } } ,
32+ { ...createFeed ( ) , ...{ path : '/feed2.xml' } }
33+ ]
34+ } ) )
4935
5036 const filePath = resolve ( nuxt . options . rootDir , join ( nuxt . options . generate . dir , 'feed.xml' ) )
5137 expect ( readFileSync ( filePath , { encoding : 'utf8' } ) ) . toMatchSnapshot ( )
5238 } )
5339
5440 test ( 'simple rss' , async ( ) => {
55- nuxt = await setupNuxt ( config )
41+ ( { nuxt } = await setup ( config ) )
5642
5743 const html = await get ( '/feed.xml' )
5844 expect ( html ) . toMatchSnapshot ( )
5945 } )
6046
6147 test ( 'simple atom' , async ( ) => {
62- nuxt = await setupNuxt ( {
48+ ( { nuxt } = await setup ( {
6349 ...config ,
6450 feed : [
6551 createFeed ( 'atom1' )
6652 ]
67- } )
53+ } ) )
6854
6955 const html = await get ( '/feed.xml' )
7056 expect ( html ) . toMatchSnapshot ( )
7157 } )
7258
7359 test ( 'simple json' , async ( ) => {
74- nuxt = await setupNuxt ( {
60+ ( { nuxt } = await setup ( {
7561 ...config ,
7662 feed : [
7763 createFeed ( 'json1' )
7864 ]
79- } )
65+ } ) )
8066
8167 const html = await get ( '/feed.xml' )
8268 expect ( html ) . toMatchSnapshot ( )
8369 } )
8470
8571 test ( 'non-latin rss' , async ( ) => {
86- nuxt = await setupNuxt ( {
72+ ( { nuxt } = await setup ( {
8773 ...config ,
8874 feed : [
8975 {
@@ -103,14 +89,14 @@ describe('module', () => {
10389 type : 'rss2'
10490 }
10591 ]
106- } )
92+ } ) )
10793
10894 const html = await get ( '/feed.xml' )
10995 expect ( html ) . toMatchSnapshot ( )
11096 } )
11197
11298 test ( 'object rss' , async ( ) => {
113- nuxt = await setupNuxt ( {
99+ ( { nuxt } = await setup ( {
114100 ...config ,
115101 feed : {
116102 data : { title : 'Feed Title' } ,
@@ -120,14 +106,14 @@ describe('module', () => {
120106 } ,
121107 type : 'rss2'
122108 }
123- } )
109+ } ) )
124110
125111 const html = await get ( '/feed.xml' )
126112 expect ( html ) . toMatchSnapshot ( )
127113 } )
128114
129115 test ( 'factory rss' , async ( ) => {
130- nuxt = await setupNuxt ( {
116+ ( { nuxt } = await setup ( {
131117 ...config ,
132118 feed : {
133119 data : { title : 'Feed Title' } ,
@@ -140,30 +126,30 @@ describe('module', () => {
140126 type : 'rss2'
141127 } )
142128 }
143- } )
129+ } ) )
144130
145131 const html = await get ( '/feed.xml' )
146132 expect ( html ) . toMatchSnapshot ( )
147133 } )
148134
149135 test ( 'function rss' , async ( ) => {
150- nuxt = await setupNuxt ( {
136+ ( { nuxt } = await setup ( {
151137 ...config ,
152138 feed : ( ) => createFeed ( )
153- } )
139+ } ) )
154140
155141 const html = await get ( '/feed.xml' )
156142 expect ( html ) . toMatchSnapshot ( )
157143 } )
158144
159145 test ( 'multi rss' , async ( ) => {
160- nuxt = await setupNuxt ( {
146+ ( { nuxt } = await setup ( {
161147 ...config ,
162148 feed : [
163149 { ...createFeed ( ) , ...{ path : '/feed1.xml' } } ,
164150 { ...createFeed ( ) , ...{ path : '/feed2.xml' } }
165151 ]
166- } )
152+ } ) )
167153
168154 const html1 = await get ( '/feed1.xml' )
169155 expect ( html1 ) . toMatchSnapshot ( )
@@ -173,12 +159,12 @@ describe('module', () => {
173159 } )
174160
175161 test ( 'no type set' , async ( ) => {
176- nuxt = await setupNuxt ( {
162+ ( { nuxt } = await setup ( {
177163 ...config ,
178164 feed : [
179165 { }
180166 ]
181- } )
167+ } ) )
182168
183169 const html = await get ( '/feed.xml' )
184170 expect ( html ) . toMatchSnapshot ( )
@@ -187,7 +173,7 @@ describe('module', () => {
187173 } )
188174
189175 test ( 'error on create feed' , async ( ) => {
190- nuxt = await setupNuxt ( {
176+ ( { nuxt } = await setup ( {
191177 ...config ,
192178 feed : [
193179 {
@@ -197,7 +183,7 @@ describe('module', () => {
197183 type : 'rss2'
198184 }
199185 ]
200- } )
186+ } ) )
201187
202188 const html = await get ( '/feed.xml' )
203189 expect ( html ) . toMatchSnapshot ( )
0 commit comments