mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-20 22:35:09 +00:00
merge
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
preload({ url }) {
|
preload({ url }) {
|
||||||
return { url };
|
if (url) return { url };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ const fetch = require('node-fetch');
|
|||||||
run('production');
|
run('production');
|
||||||
run('development');
|
run('development');
|
||||||
|
|
||||||
|
Nightmare.action('page', {
|
||||||
|
title(done) {
|
||||||
|
this.evaluate_now(() => document.querySelector('h1').textContent, done);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function run(env) {
|
function run(env) {
|
||||||
describe(`env=${env}`, function () {
|
describe(`env=${env}`, function () {
|
||||||
this.timeout(20000);
|
this.timeout(20000);
|
||||||
@@ -149,57 +155,39 @@ function run(env) {
|
|||||||
return nightmare.end();
|
return nightmare.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('serves /', () => {
|
it('serves /', async () => {
|
||||||
return nightmare
|
const title = await nightmare.goto(base).page.title();
|
||||||
.goto(base)
|
assert.equal(title, 'Great success!');
|
||||||
.evaluate(() => document.querySelector('h1').textContent)
|
|
||||||
.then(title => {
|
|
||||||
assert.equal(title, 'Great success!');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('serves static route', () => {
|
it('serves static route', async () => {
|
||||||
return nightmare
|
const title = await nightmare.goto(`${base}/about`).page.title();
|
||||||
.goto(`${base}/about`)
|
assert.equal(title, 'About this site');
|
||||||
.evaluate(() => document.querySelector('h1').textContent)
|
|
||||||
.then(title => {
|
|
||||||
assert.equal(title, 'About this site');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('serves dynamic route', () => {
|
it('serves dynamic route', async () => {
|
||||||
return nightmare
|
const title = await nightmare.goto(`${base}/blog/what-is-sapper`).page.title();
|
||||||
.goto(`${base}/blog/what-is-sapper`)
|
assert.equal(title, 'What is Sapper?');
|
||||||
.evaluate(() => document.querySelector('h1').textContent)
|
|
||||||
.then(title => {
|
|
||||||
assert.equal(title, 'What is Sapper?');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('navigates to a new page without reloading', () => {
|
it('navigates to a new page without reloading', async () => {
|
||||||
let requests;
|
await nightmare.goto(base).wait(() => window.READY).wait(200);
|
||||||
return nightmare
|
|
||||||
.goto(base).wait(() => window.READY).wait(200)
|
|
||||||
.then(() => {
|
|
||||||
return capture(() => {
|
|
||||||
return nightmare.click('a[href="/about"]');
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(reqs => {
|
|
||||||
requests = reqs;
|
|
||||||
|
|
||||||
return nightmare.path();
|
const requests = await capture(async () => {
|
||||||
})
|
await nightmare.click('a[href="/about"]');
|
||||||
.then(path => {
|
});
|
||||||
assert.equal(path, '/about');
|
|
||||||
|
|
||||||
return nightmare.evaluate(() => document.title);
|
assert.equal(
|
||||||
})
|
await nightmare.path(),
|
||||||
.then(title => {
|
'/about'
|
||||||
assert.equal(title, 'About');
|
);
|
||||||
|
|
||||||
assert.deepEqual(requests.map(r => r.url), []);
|
assert.equal(
|
||||||
});
|
await nightmare.title(),
|
||||||
|
'About'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(requests.map(r => r.url), []);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('navigates programmatically', () => {
|
it('navigates programmatically', () => {
|
||||||
@@ -208,11 +196,12 @@ function run(env) {
|
|||||||
.wait(() => window.READY)
|
.wait(() => window.READY)
|
||||||
.click('.goto')
|
.click('.goto')
|
||||||
.wait(() => window.location.pathname === '/blog/what-is-sapper')
|
.wait(() => window.location.pathname === '/blog/what-is-sapper')
|
||||||
.wait(100)
|
.wait(100);
|
||||||
.then(() => nightmare.evaluate(() => document.title))
|
|
||||||
.then(title => {
|
assert.equal(
|
||||||
assert.equal(title, 'What is Sapper?');
|
await nightmare.title(),
|
||||||
});
|
'What is Sapper?'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prefetches programmatically', () => {
|
it('prefetches programmatically', () => {
|
||||||
@@ -277,51 +266,41 @@ function run(env) {
|
|||||||
.click('a[href="/slow-preload"]')
|
.click('a[href="/slow-preload"]')
|
||||||
.wait(100)
|
.wait(100)
|
||||||
.click('a[href="/about"]')
|
.click('a[href="/about"]')
|
||||||
.wait(100)
|
.wait(100);
|
||||||
.then(() => nightmare.path())
|
|
||||||
.then(path => {
|
|
||||||
assert.equal(path, '/about');
|
|
||||||
|
|
||||||
return nightmare.evaluate(() => document.querySelector('h1').textContent);
|
assert.equal(
|
||||||
})
|
await nightmare.path(),
|
||||||
.then(header_text => {
|
'/about'
|
||||||
assert.equal(header_text, 'About this site');
|
);
|
||||||
|
|
||||||
return nightmare.evaluate(() => window.fulfil({})).wait(100);
|
assert.equal(
|
||||||
})
|
await nightmare.page.title(),
|
||||||
.then(() => nightmare.path())
|
'About this site'
|
||||||
.then(path => {
|
);
|
||||||
assert.equal(path, '/about');
|
|
||||||
|
|
||||||
return nightmare.evaluate(() => document.querySelector('h1').textContent);
|
await nightmare
|
||||||
})
|
.evaluate(() => window.fulfil({}))
|
||||||
.then(header_text => {
|
.wait(100);
|
||||||
assert.equal(header_text, 'About this site');
|
|
||||||
|
|
||||||
return nightmare.evaluate(() => window.fulfil({})).wait(100);
|
assert.equal(
|
||||||
});
|
await nightmare.path(),
|
||||||
|
'/about'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await nightmare.page.title(),
|
||||||
|
'About this site'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes entire request object to preload', () => {
|
it('passes entire request object to preload', async () => {
|
||||||
return nightmare
|
await nightmare
|
||||||
.goto(`${base}/show-url`)
|
.goto(`${base}/show-url`)
|
||||||
.evaluate(() => document.querySelector('p').innerHTML)
|
.evaluate(() => document.querySelector('p').innerHTML)
|
||||||
.then(html => {
|
.end().then(html => {
|
||||||
assert.equal(html, `URL is /show-url`);
|
assert.equal(html, `URL is /show-url`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls a delete handler', () => {
|
|
||||||
return nightmare
|
|
||||||
.goto(`${base}/delete-test`)
|
|
||||||
.wait(() => window.READY)
|
|
||||||
.click('.del')
|
|
||||||
.wait(() => window.deleted)
|
|
||||||
.evaluate(() => window.deleted.id)
|
|
||||||
.then(id => {
|
|
||||||
assert.equal(id, 42);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('headers', () => {
|
describe('headers', () => {
|
||||||
@@ -355,4 +334,4 @@ function exec(cmd) {
|
|||||||
fulfil();
|
fulfil();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user