mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-19 22:05:20 +00:00
Merge branch 'fix-tests-without-async' into gh-3
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);
|
||||||
@@ -150,55 +156,38 @@ function run(env) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('serves /', () => {
|
it('serves /', () => {
|
||||||
return nightmare
|
return nightmare.goto(base).page.title().then(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', () => {
|
||||||
return nightmare
|
return nightmare.goto(`${base}/about`).page.title().then(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', () => {
|
||||||
return nightmare
|
return nightmare.goto(`${base}/blog/what-is-sapper`).page.title().then(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', () => {
|
||||||
let requests;
|
return nightmare.goto(base).wait(() => window.READY).wait(200)
|
||||||
return nightmare
|
|
||||||
.goto(base).wait(() => window.READY).wait(200)
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return capture(() => {
|
return capture(() => nightmare.click('a[href="/about"]'));
|
||||||
return nightmare.click('a[href="/about"]');
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.then(reqs => {
|
.then(requests => {
|
||||||
requests = reqs;
|
assert.deepEqual(requests.map(r => r.url), []);
|
||||||
|
|
||||||
return nightmare.path();
|
return nightmare.path();
|
||||||
})
|
})
|
||||||
.then(path => {
|
.then(path => {
|
||||||
assert.equal(path, '/about');
|
assert.equal(path, '/about');
|
||||||
|
return nightmare.title();
|
||||||
return nightmare.evaluate(() => document.title);
|
|
||||||
})
|
})
|
||||||
.then(title => {
|
.then(title => {
|
||||||
assert.equal(title, 'About');
|
assert.equal(title, 'About');
|
||||||
|
|
||||||
assert.deepEqual(requests.map(r => r.url), []);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -209,7 +198,7 @@ function run(env) {
|
|||||||
.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))
|
.title()
|
||||||
.then(title => {
|
.then(title => {
|
||||||
assert.equal(title, 'What is Sapper?');
|
assert.equal(title, 'What is Sapper?');
|
||||||
});
|
});
|
||||||
@@ -281,45 +270,29 @@ function run(env) {
|
|||||||
.then(() => nightmare.path())
|
.then(() => nightmare.path())
|
||||||
.then(path => {
|
.then(path => {
|
||||||
assert.equal(path, '/about');
|
assert.equal(path, '/about');
|
||||||
|
return nightmare.title();
|
||||||
return nightmare.evaluate(() => document.querySelector('h1').textContent);
|
|
||||||
})
|
})
|
||||||
.then(header_text => {
|
.then(title => {
|
||||||
assert.equal(header_text, 'About this site');
|
assert.equal(title, 'About');
|
||||||
|
|
||||||
return nightmare.evaluate(() => window.fulfil({})).wait(100);
|
return nightmare.evaluate(() => window.fulfil({})).wait(100);
|
||||||
})
|
})
|
||||||
.then(() => nightmare.path())
|
.then(() => nightmare.path())
|
||||||
.then(path => {
|
.then(path => {
|
||||||
assert.equal(path, '/about');
|
assert.equal(path, '/about');
|
||||||
|
return nightmare.title();
|
||||||
return nightmare.evaluate(() => document.querySelector('h1').textContent);
|
|
||||||
})
|
})
|
||||||
.then(header_text => {
|
.then(title => {
|
||||||
assert.equal(header_text, 'About this site');
|
assert.equal(title, 'About');
|
||||||
|
|
||||||
return nightmare.evaluate(() => window.fulfil({})).wait(100);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes entire request object to preload', () => {
|
it('passes entire request object to preload', () => {
|
||||||
return nightmare
|
return nightmare
|
||||||
.goto(`${base}/show-url`)
|
.goto(`${base}/show-url`)
|
||||||
.evaluate(() => document.querySelector('p').innerHTML)
|
|
||||||
.then(html => {
|
|
||||||
assert.equal(html, `URL is /show-url`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls a delete handler', () => {
|
|
||||||
return nightmare
|
|
||||||
.goto(`${base}/delete-test`)
|
|
||||||
.wait(() => window.READY)
|
.wait(() => window.READY)
|
||||||
.click('.del')
|
.evaluate(() => document.querySelector('p').innerHTML)
|
||||||
.wait(() => window.deleted)
|
.end().then(html => {
|
||||||
.evaluate(() => window.deleted.id)
|
assert.equal(html, `URL is /show-url`);
|
||||||
.then(id => {
|
|
||||||
assert.equal(id, 42);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user