Skip to content

Commit

Permalink
chore: fix Nuxt ecosystem ci
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Aug 26, 2024
1 parent 3cb8a2a commit 871bbaf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ git checkout -b my-new-branch

Before running tests, you'll need to install [Playwright](https://playwright.dev/) Chromium browser: `pnpm playwright install chromium`.

Run `nr test` in `@vite-pwa/nuxt`'s root folder.
Run `nr test:local` in `@vite-pwa/nuxt`'s root folder.


3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"test:generate:serve": "PORT=4173 serve playground/dist",
"test:build": "nr dev:build && TEST_BUILD=true vitest run && TEST_BUILD=true playwright test",
"test:generate": "nr dev:generate && vitest run && playwright test",
"test": "nr test:build && nr test:generate",
"test:local": "nr test:build && nr test:generate",
"test": "NUXT_ECOSYSTEM_CI=true nr test:build && nr test:generate",
"test:with-build": "nr dev:prepare && nr prepack && nr test"
},
"dependencies": {
Expand Down
16 changes: 12 additions & 4 deletions test/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import process from 'node:process'
import { describe, expect, it } from 'vitest'

const build = process.env.TEST_BUILD === 'true'
const nuxt3_13 = process.env.NUXT_ECOSYSTEM_CI === 'true'

describe(`test-${build ? 'build' : 'generate'}`, () => {
it('service worker is generated: ', () => {
Expand All @@ -16,10 +17,17 @@ describe(`test-${build ? 'build' : 'generate'}`, () => {
expect(existsSync(webManifest), `${webManifest} doesn't exist`).toBeTruthy()
const swContent = readFileSync(swName, 'utf-8')
let match: RegExpMatchArray | null
match = swContent.match(/define\(\["\.\/(workbox-\w+)"/)
expect(match && match.length === 2, `workbox-***.js entry not found in ${swName}`).toBeTruthy()
const workboxName = `./playground/${build ? '.output/public' : 'dist'}/${match?.[1]}.js`
expect(existsSync(workboxName), `${workboxName} doesn't exist`).toBeTruthy()
// vite5/rollup4 inlining workbox-***.js in the sw.js
if (nuxt3_13) {
match = swContent.match(/define\(\["\.\/(workbox-\w+)"/)
expect(match, `workbox-***.js entry found in ${swName}`).toBeFalsy()
}
else {
match = swContent.match(/define\(\["\.\/(workbox-\w+)"/)
expect(match && match.length === 2, `workbox-***.js entry not found in ${swName}`).toBeTruthy()
const workboxName = `./playground/${build ? '.output/public' : 'dist'}/${match?.[1]}.js`
expect(existsSync(workboxName), `${workboxName} doesn't exist`).toBeTruthy()
}
match = swContent.match(/url:\s*"manifest\.webmanifest"/)
expect(match && match.length === 1, 'missing manifest.webmanifest in sw precache manifest').toBeTruthy()
match = swContent.match(/url:\s*"\/"/)
Expand Down

0 comments on commit 871bbaf

Please sign in to comment.