1
- const { defaultFiles, getPage } = require ( './testsTools.js' ) ;
1
+ const { defaultFiles, createPage } = require ( './testsTools.js' ) ;
2
2
3
- test ( 'text-only tamplate' , async ( ) => {
4
3
5
- const page = await getPage ( {
4
+ test ( 'text-only template' , async ( ) => {
5
+
6
+ const { page, output } = await createPage ( {
6
7
files : {
7
8
...defaultFiles ,
8
9
'/component.vue' : `
9
10
<template>
10
- Hello World ! <b id="done"/>
11
+ Hello World !
11
12
</template>
12
13
`
13
14
}
14
15
} ) ;
15
16
16
- await page . waitForSelector ( '#done' ) ;
17
17
await expect ( page . $eval ( '#app' , el => el . textContent . trim ( ) ) ) . resolves . toBe ( 'Hello World !' ) ;
18
+
18
19
await page . close ( ) ;
19
20
} ) ;
20
21
21
22
22
23
test ( 'properly detect and reports errors in template' , async ( ) => {
23
24
24
- const page = await getPage ( {
25
+ const { page, output } = await createPage ( {
25
26
files : {
26
27
...defaultFiles ,
27
28
'/component.vue' : `
28
29
<template>
29
- Hello World ! {{ msg } <b id="done"/>
30
+ Hello World ! {{ msg }
30
31
</template>
31
32
`
32
33
}
33
34
} ) ;
34
35
35
- await page . waitForSelector ( '#done' ) ;
36
- await expect ( page . console . some ( e => e . type === 'error' && e . content [ 0 ] === 'SFC template' ) ) . toBe ( true ) ;
36
+ //await page.waitForSelector('#done');
37
+ await expect ( output . some ( e => e . type === 'error' && e . content [ 0 ] === 'SFC template' ) ) . toBe ( true ) ;
38
+ //await new Promise(resolve => page.on('consoleValues', ({ type, args }) => type === 'error' && args[0] === 'SFC template' && resolve() ));
39
+
37
40
await page . close ( ) ;
38
41
} ) ;
39
42
40
43
41
44
test ( 'properly detect and reports errors in style' , async ( ) => {
42
45
43
- const page = await getPage ( {
46
+ const { page, output } = await createPage ( {
44
47
files : {
45
48
...defaultFiles ,
46
49
'/component.vue' : `
47
50
<template>
48
- Hello World ! <b id="done"/>
51
+ Hello World !
49
52
</template>
50
53
<style>
51
54
body
@@ -56,15 +59,15 @@ test('properly detect and reports errors in style', async () => {
56
59
}
57
60
} ) ;
58
61
59
- await page . waitForSelector ( '#done' ) ;
60
- await expect ( page . console . some ( e => e . type === 'error' && e . content [ 0 ] === 'SFC style' ) ) . toBe ( true ) ;
62
+ await expect ( output . some ( e => e . type === 'error' && e . content [ 0 ] === 'SFC style' ) ) . toBe ( true ) ;
63
+
61
64
await page . close ( ) ;
62
65
} ) ;
63
66
64
67
65
68
test ( 'properly detect and reports errors in script' , async ( ) => {
66
69
67
- const page = await getPage ( {
70
+ const { page, output } = await createPage ( {
68
71
files : {
69
72
...defaultFiles ,
70
73
'/component.vue' : `
@@ -75,21 +78,21 @@ test('properly detect and reports errors in script', async () => {
75
78
}
76
79
} ) ;
77
80
78
- await new Promise ( resolve => setTimeout ( resolve , 500 ) ) ;
79
- await expect ( page . console . some ( e => e . type === 'error' && e . content [ 0 ] === 'SFC script' ) ) . toBe ( true ) ;
81
+ await expect ( output . some ( e => e . type === 'error' && e . content [ 0 ] === 'SFC script' ) ) . toBe ( true ) ;
82
+
80
83
await page . close ( ) ;
81
84
} ) ;
82
85
83
86
84
87
85
88
test ( 'all blocks' , async ( ) => {
86
89
87
- const page = await getPage ( {
90
+ const { page, output } = await createPage ( {
88
91
files : {
89
92
...defaultFiles ,
90
93
'/component.vue' : `
91
94
<template>
92
- <b>Hello {{ msg }} !</b><b id="done"/>
95
+ <b>Hello {{ msg }} !</b>
93
96
</template>
94
97
<style scoped>
95
98
b { color: red; }
@@ -103,15 +106,15 @@ test('all blocks', async () => {
103
106
}
104
107
} ) ;
105
108
106
- await new Promise ( resolve => setTimeout ( resolve , 500 ) ) ;
107
- await expect ( ! page . console . some ( e => e . type === 'error' ) ) . toBe ( true ) ;
109
+ await expect ( ! output . some ( e => e . type === 'error' ) ) . toBe ( true ) ;
110
+
108
111
await page . close ( ) ;
109
112
} ) ;
110
113
111
114
112
115
test ( 'invalid require' , async ( ) => {
113
116
114
- const page = await getPage ( {
117
+ const { page, output } = await createPage ( {
115
118
files : {
116
119
...defaultFiles ,
117
120
'/component.vue' : `
@@ -122,8 +125,8 @@ test('invalid require', async () => {
122
125
}
123
126
} ) ;
124
127
125
- await new Promise ( resolve => setTimeout ( resolve , 1500 ) ) ;
126
- await expect ( page . console . some ( e => e . type === 'pageerror' && String ( e . content ) . includes ( 'HttpError' ) ) ) . toBe ( true ) ;
128
+ await expect ( output . some ( e => e . type === 'pageerror' && String ( e . content ) . includes ( 'HttpError' ) ) ) . toBe ( true ) ;
129
+
127
130
await page . close ( ) ;
128
131
} ) ;
129
132
0 commit comments