-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test1 * fixed test * removed console.log * changeset * pnpm-lock * fixed test again * fta * fta2 * fix: wait for fetch * -fixed test template * empty Co-authored-by: Matthew Phillips <[email protected]> Co-authored-by: Nate Moore <[email protected]> Co-authored-by: Nate Moore <[email protected]> Co-authored-by: My Name <[email protected]>
- Loading branch information
1 parent
fad25ae
commit 5a674f9
Showing
9 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/prefetch': minor | ||
--- | ||
|
||
Prefetch CSS files once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/integrations/prefetch/test/fixtures/style-prefetch/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import prefetch from '@astrojs/prefetch'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [prefetch()], | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/integrations/prefetch/test/fixtures/style-prefetch/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/astro-prefetch", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@astrojs/prefetch": "workspace:*", | ||
"astro": "workspace:*" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Home</title> | ||
</head> | ||
<body> | ||
<h1>Home</h1> | ||
<ul> | ||
<li><a href="/style1" rel="prefetch">1</a></li> | ||
<li><a href="/style2" rel="prefetch">2</a></li> | ||
</ul> | ||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style1.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Style1</title> | ||
<link rel="stylesheet" href="/main.css"> | ||
</head> | ||
<body> | ||
<h1>Style1</h1> | ||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style2.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Style2</title> | ||
<link rel="stylesheet" href="/main.css"> | ||
</head> | ||
<body> | ||
<h1>Style2</h1> | ||
</body> | ||
</html> |
55 changes: 55 additions & 0 deletions
55
packages/integrations/prefetch/test/style-prefetch.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { expect } from '@playwright/test'; | ||
import { testFactory } from './test-utils.js'; | ||
|
||
const test = testFactory({ root: './fixtures/style-prefetch/' }); | ||
|
||
test.describe('Style prefetch', () => { | ||
test.describe('dev', () => { | ||
let devServer; | ||
|
||
test.beforeEach(async ({ astro }) => { | ||
devServer = await astro.startDevServer(); | ||
}); | ||
|
||
test.afterEach(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
testPrefetch(); | ||
}); | ||
|
||
test.describe('build', () => { | ||
let previewServer; | ||
|
||
test.beforeAll(async ({ astro }) => { | ||
await astro.build(); | ||
previewServer = await astro.preview(); | ||
}); | ||
|
||
// important: close preview server (free up port and connection) | ||
test.afterAll(async () => { | ||
await previewServer.stop(); | ||
}); | ||
|
||
testPrefetch(); | ||
}); | ||
|
||
function testPrefetch() { | ||
test.describe('prefetches rel="prefetch" links', () => { | ||
test('style fetching', async ({ page, astro }) => { | ||
const requests = []; | ||
|
||
page.on('request', async (request) => requests.push(request.url())); | ||
|
||
await page.goto(astro.resolveUrl('/')); | ||
|
||
await page.waitForLoadState('networkidle'); | ||
|
||
await expect(requests.filter(req => req.includes('/style1'))).toBeTruthy(); | ||
await expect(requests.filter(req => req.includes('/style2'))).toBeTruthy(); | ||
const cssRequestCount = requests.filter(req => req.includes('/main.css')).length; | ||
await expect(cssRequestCount).toBe(1); | ||
}); | ||
}); | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.