2021-05-11 23:31:52 +00:00
|
|
|
import { suite } from 'uvu';
|
|
|
|
import * as assert from 'uvu/assert';
|
|
|
|
import { doc } from './test-utils.js';
|
|
|
|
import { setup } from './helpers.js';
|
|
|
|
|
|
|
|
const Global = suite('Astro.*');
|
|
|
|
|
|
|
|
setup(Global, './fixtures/astro-global');
|
|
|
|
|
|
|
|
Global('Astro.request.url', async (context) => {
|
|
|
|
const result = await context.runtime.load('/');
|
2021-07-20 19:22:29 +00:00
|
|
|
assert.ok(!result.error, `build error: ${result.error}`);
|
2021-05-11 23:31:52 +00:00
|
|
|
|
|
|
|
const $ = doc(result.contents);
|
|
|
|
assert.equal($('#pathname').text(), '/');
|
2021-08-03 12:17:03 +00:00
|
|
|
assert.equal($('#child-pathname').text(), '/');
|
|
|
|
assert.equal($('#nested-child-pathname').text(), '/');
|
2021-05-11 23:31:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Global('Astro.request.canonicalURL', async (context) => {
|
|
|
|
// given a URL, expect the following canonical URL
|
|
|
|
const canonicalURLs = {
|
2021-07-26 18:42:24 +00:00
|
|
|
'/': 'https://mysite.dev/blog/',
|
|
|
|
'/post/post': 'https://mysite.dev/blog/post/post/',
|
2021-08-11 22:04:09 +00:00
|
|
|
'/posts/1': 'https://mysite.dev/blog/posts/',
|
2021-07-26 18:42:24 +00:00
|
|
|
'/posts/2': 'https://mysite.dev/blog/posts/2/',
|
2021-05-11 23:31:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const [url, canonicalURL] of Object.entries(canonicalURLs)) {
|
|
|
|
const result = await context.runtime.load(url);
|
|
|
|
const $ = doc(result.contents);
|
|
|
|
assert.equal($('link[rel="canonical"]').attr('href'), canonicalURL);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Global('Astro.site', async (context) => {
|
|
|
|
const result = await context.runtime.load('/');
|
2021-07-20 19:22:29 +00:00
|
|
|
assert.ok(!result.error, `build error: ${result.error}`);
|
2021-05-11 23:31:52 +00:00
|
|
|
|
|
|
|
const $ = doc(result.contents);
|
2021-07-26 18:42:24 +00:00
|
|
|
assert.equal($('#site').attr('href'), 'https://mysite.dev/blog/');
|
2021-05-11 23:31:52 +00:00
|
|
|
});
|
|
|
|
|
2021-08-16 20:43:06 +00:00
|
|
|
Global('Astro.resolve in development', async (context) => {
|
|
|
|
const result = await context.runtime.load('/resolve');
|
|
|
|
assert.ok(!result.error, `build error: ${result.error}`);
|
|
|
|
|
|
|
|
const html = result.contents;
|
|
|
|
const $ = doc(html);
|
|
|
|
assert.equal($('img').attr('src'), '/_astro/src/images/penguin.png');
|
2021-08-24 17:38:07 +00:00
|
|
|
assert.equal($('#inner-child img').attr('src'), '/_astro/src/components/nested/images/penguin.png');
|
2021-08-16 20:43:06 +00:00
|
|
|
});
|
|
|
|
|
2021-08-16 20:44:46 +00:00
|
|
|
Global.run();
|