Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit bd656cf

Browse files
committed
Merge branch 'fix-tests-without-async' into gh-3
2 parents c4b4bd5 + 2abfdb0 commit bd656cf

File tree

2 files changed

+32
-59
lines changed

2 files changed

+32
-59
lines changed

test/app/routes/show-url.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<script>
44
export default {
55
preload({ url }) {
6-
return { url };
6+
if (url) return { url };
77
}
88
};
9-
</script>
9+
</script>

test/common/test.js

+30-57
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ const fetch = require('node-fetch');
99
run('production');
1010
run('development');
1111

12+
Nightmare.action('page', {
13+
title(done) {
14+
this.evaluate_now(() => document.querySelector('h1').textContent, done);
15+
}
16+
});
17+
1218
function run(env) {
1319
describe(`env=${env}`, function () {
1420
this.timeout(20000);
@@ -150,55 +156,38 @@ function run(env) {
150156
});
151157

152158
it('serves /', () => {
153-
return nightmare
154-
.goto(base)
155-
.evaluate(() => document.querySelector('h1').textContent)
156-
.then(title => {
157-
assert.equal(title, 'Great success!');
158-
});
159+
return nightmare.goto(base).page.title().then(title => {
160+
assert.equal(title, 'Great success!');
161+
});
159162
});
160163

161164
it('serves static route', () => {
162-
return nightmare
163-
.goto(`${base}/about`)
164-
.evaluate(() => document.querySelector('h1').textContent)
165-
.then(title => {
166-
assert.equal(title, 'About this site');
167-
});
165+
return nightmare.goto(`${base}/about`).page.title().then(title => {
166+
assert.equal(title, 'About this site');
167+
});
168168
});
169169

170170
it('serves dynamic route', () => {
171-
return nightmare
172-
.goto(`${base}/blog/what-is-sapper`)
173-
.evaluate(() => document.querySelector('h1').textContent)
174-
.then(title => {
175-
assert.equal(title, 'What is Sapper?');
176-
});
171+
return nightmare.goto(`${base}/blog/what-is-sapper`).page.title().then(title => {
172+
assert.equal(title, 'What is Sapper?');
173+
});
177174
});
178175

179176
it('navigates to a new page without reloading', () => {
180-
let requests;
181-
return nightmare
182-
.goto(base).wait(() => window.READY).wait(200)
177+
return nightmare.goto(base).wait(() => window.READY).wait(200)
183178
.then(() => {
184-
return capture(() => {
185-
return nightmare.click('a[href="/about"]');
186-
});
179+
return capture(() => nightmare.click('a[href="/about"]'));
187180
})
188-
.then(reqs => {
189-
requests = reqs;
190-
181+
.then(requests => {
182+
assert.deepEqual(requests.map(r => r.url), []);
191183
return nightmare.path();
192184
})
193185
.then(path => {
194186
assert.equal(path, '/about');
195-
196-
return nightmare.evaluate(() => document.title);
187+
return nightmare.title();
197188
})
198189
.then(title => {
199190
assert.equal(title, 'About');
200-
201-
assert.deepEqual(requests.map(r => r.url), []);
202191
});
203192
});
204193

@@ -209,7 +198,7 @@ function run(env) {
209198
.click('.goto')
210199
.wait(() => window.location.pathname === '/blog/what-is-sapper')
211200
.wait(100)
212-
.then(() => nightmare.evaluate(() => document.title))
201+
.title()
213202
.then(title => {
214203
assert.equal(title, 'What is Sapper?');
215204
});
@@ -281,47 +270,31 @@ function run(env) {
281270
.then(() => nightmare.path())
282271
.then(path => {
283272
assert.equal(path, '/about');
284-
285-
return nightmare.evaluate(() => document.querySelector('h1').textContent);
273+
return nightmare.title();
286274
})
287-
.then(header_text => {
288-
assert.equal(header_text, 'About this site');
289-
275+
.then(title => {
276+
assert.equal(title, 'About');
290277
return nightmare.evaluate(() => window.fulfil({})).wait(100);
291278
})
292279
.then(() => nightmare.path())
293280
.then(path => {
294281
assert.equal(path, '/about');
295-
296-
return nightmare.evaluate(() => document.querySelector('h1').textContent);
282+
return nightmare.title();
297283
})
298-
.then(header_text => {
299-
assert.equal(header_text, 'About this site');
300-
301-
return nightmare.evaluate(() => window.fulfil({})).wait(100);
284+
.then(title => {
285+
assert.equal(title, 'About');
302286
});
303287
});
304288

305289
it('passes entire request object to preload', () => {
306290
return nightmare
307291
.goto(`${base}/show-url`)
292+
.wait(() => window.READY)
308293
.evaluate(() => document.querySelector('p').innerHTML)
309-
.then(html => {
294+
.end().then(html => {
310295
assert.equal(html, `URL is /show-url`);
311296
});
312297
});
313-
314-
it('calls a delete handler', () => {
315-
return nightmare
316-
.goto(`${base}/delete-test`)
317-
.wait(() => window.READY)
318-
.click('.del')
319-
.wait(() => window.deleted)
320-
.evaluate(() => window.deleted.id)
321-
.then(id => {
322-
assert.equal(id, 42);
323-
});
324-
});
325298
});
326299

327300
describe('headers', () => {
@@ -355,4 +328,4 @@ function exec(cmd) {
355328
fulfil();
356329
});
357330
});
358-
}
331+
}

0 commit comments

Comments
 (0)