Skip to content

Commit

Permalink
refactor: change how tests are run
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Aug 16, 2023
1 parent d64b11c commit 1095ce6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
6 changes: 3 additions & 3 deletions packages/astro/test/astro-assets-prefix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Assets Prefix - Static', () => {
});
});

describe('Assets Prefix - Static with path prefix', () => {
describe('Assets Prefix - with path prefix', () => {
let fixture;

before(async () => {
Expand All @@ -86,7 +86,7 @@ describe('Assets Prefix - Static with path prefix', () => {
});
});

describe('Assets Prefix - Server', () => {
describe('Assets Prefix, server', () => {
let app;

before(async () => {
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('Assets Prefix - Server', () => {
});
});

describe('Assets Prefix - Server with path prefix', () => {
describe('Assets Prefix, with path prefix', () => {
let app;

before(async () => {
Expand Down
64 changes: 34 additions & 30 deletions packages/astro/test/ssr-hoisted-script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,54 @@ import { load as cheerioLoad } from 'cheerio';
import { loadFixture } from './test-utils.js';
import testAdapter from './test-adapter.js';

async function fetchHTML(fixture, path) {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com' + path);
const response = await app.render(request);
const html = await response.text();
return html;
}

describe('Hoisted scripts in SSR', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/ssr-hoisted-script/',
output: 'server',
adapter: testAdapter(),
});
await fixture.build();
});

async function fetchHTML(path) {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com' + path);
const response = await app.render(request);
const html = await response.text();
return html;
}

it('Inlined scripts get included', async () => {
const html = await fetchHTML('/');
const $ = cheerioLoad(html);
expect($('script').length).to.equal(1);
});

describe('base path', () => {
const base = '/hello';

describe('without base path', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/ssr-hoisted-script/',
output: 'server',
adapter: testAdapter(),
base,
});
await fixture.build();
});

it('Inlined scripts get included without base path in the script', async () => {
const html = await fetchHTML('/hello/');
it('Inlined scripts get included', async () => {
const html = await fetchHTML(fixture, '/');
const $ = cheerioLoad(html);
expect($('script').html()).to.equal('console.log("hello world");\n');
expect($('script').length).to.equal(1);
});
});
});

describe('Hoisted scripts in SSR with base path', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
const base = '/hello';

before(async () => {
fixture = await loadFixture({
root: './fixtures/ssr-hoisted-script/',
output: 'server',
adapter: testAdapter(),
base,
});
await fixture.build();
});

it('Inlined scripts get included without base path in the script', async () => {
const html = await fetchHTML(fixture, '/hello/');
const $ = cheerioLoad(html);
expect($('script').html()).to.equal('console.log("hello world");\n');
});
});

0 comments on commit 1095ce6

Please sign in to comment.