@@ -2,6 +2,9 @@ import { test } from 'uvu';
2
2
import * as assert from 'uvu/assert' ;
3
3
4
4
import { setupTest , teardownTest , loadFixture , viteBuildCli } from './lib/lifecycle.js' ;
5
+ import { writeFixtureFile } from './lib/utils.js' ;
6
+
7
+ const writeConfig = async ( dir , content ) => writeFixtureFile ( dir , 'vite.config.js' , content ) ;
5
8
6
9
let env ;
7
10
test . before . each ( async ( ) => {
@@ -12,19 +15,45 @@ test.after.each(async () => {
12
15
await teardownTest ( env ) ;
13
16
} ) ;
14
17
15
- test ( 'Should support the `prerenderScript` plugin option ' , async ( ) => {
18
+ test ( 'Should log which routes were prerendered & where they were discovered ' , async ( ) => {
16
19
await loadFixture ( 'logs/prerendered-routes' , env ) ;
17
20
const output = await viteBuildCli ( env . tmp . path ) ;
18
21
await output . done ;
19
22
20
- const idx = output . stdout . findIndex ( ( line ) => line . includes ( 'Prerendered' ) ) ;
21
23
// The prerender info is pushed as a single log line
22
- const stdout = output . stdout . slice ( idx ) [ 0 ] ;
24
+ const stdout = output . stdout . find ( ( line ) => line . includes ( 'Prerendered' ) ) ;
23
25
24
26
assert . match ( stdout , 'Prerendered 3 pages:\n' ) ;
25
27
assert . match ( stdout , '/\n' ) ;
26
28
assert . match ( stdout , '/foo [from /]\n' ) ;
27
29
assert . match ( stdout , '/bar [from /foo]\n' ) ;
28
30
} ) ;
29
31
32
+ test ( 'Should strip sourcemap sizes from logs if user has not enabled sourcemaps' , async ( ) => {
33
+ await loadFixture ( 'logs/prerendered-routes' , env ) ;
34
+ const output = await viteBuildCli ( env . tmp . path ) ;
35
+ await output . done ;
36
+
37
+ const stdout = output . stdout . find ( ( line ) => / d i s t \/ a s s e t s \/ i n d e x .* \. j s / . test ( line ) ) ;
38
+ assert . not . match ( stdout , '│ map:' ) ;
39
+ } ) ;
40
+
41
+ test ( 'Should preserve sourcemap sizes from logs if user has enabled sourcemaps' , async ( ) => {
42
+ await loadFixture ( 'logs/prerendered-routes' , env ) ;
43
+ await writeConfig ( env . tmp . path , `
44
+ import { defineConfig } from 'vite';
45
+ import { vitePrerenderPlugin } from 'vite-prerender-plugin';
46
+
47
+ export default defineConfig({
48
+ build: { sourcemap: true },
49
+ plugins: [vitePrerenderPlugin()],
50
+ });
51
+ ` ) ;
52
+ const output = await viteBuildCli ( env . tmp . path ) ;
53
+ await output . done ;
54
+
55
+ const stdout = output . stdout . find ( ( line ) => / d i s t \/ a s s e t s \/ i n d e x .* \. j s / . test ( line ) ) ;
56
+ assert . match ( stdout , '│ map:' ) ;
57
+ } ) ;
58
+
30
59
test . run ( ) ;
0 commit comments