Skip to content

Commit

Permalink
feat: dynamic import retry plugin [KM-865]
Browse files Browse the repository at this point in the history
  • Loading branch information
2eha0 committed Jan 7, 2025
1 parent 6feb1ae commit 77c17e6
Show file tree
Hide file tree
Showing 27 changed files with 2,065 additions and 21 deletions.
15 changes: 15 additions & 0 deletions .github/actions/setup-pnpm-with-dependencies/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,18 @@ runs:
with:
path: './node_modules'
key: ${{ steps.node-version.outputs.cache-key }}

- name: Set Playwright path
shell: bash
run: echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/playwright-bin" >> $GITHUB_ENV

- name: Cache Playwright's binary
uses: actions/cache@v4
with:
key: playwright-bin-v1
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}

- name: Install Playwright
shell: bash
# does not need to explicitly set chromium after https://github.com/microsoft/playwright/issues/14862 is solved
run: pnpm playwright install chromium
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ dist

# Local History
.history

playground-temp
temp
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,20 @@ pnpm lint:fix
Unit tests are run with [Vitest](https://vitest.dev/).

```shell
# Run tests
# Run tests both serve and build mode
pnpm test
# Run tests in the Vitest UI
pnpm test:ui
# Run serve mode tests
pnpm test-serve
# Run build mode tests
pnpm test-build
# Debug serve mode tests
pnpm debug-serve
# Debug build mode tests and keep build artifacts
pnpm debug-build
```

### Build
Expand Down
1 change: 1 addition & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineBuildConfig({
// Each separate plugin's entry file should be listed here
entries: [
'./src/plugin-example-one/index.ts',
'./src/dynamic-import-retry/index.ts',
],
// Generates .d.ts declaration file(s)
declaration: true,
Expand Down
28 changes: 25 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
"scripts": {
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "vitest run --passWithNoTests",
"test:ui": "vitest --ui --passWithNoTests",
"test": "run-s test-serve test-build",
"test-serve": "vitest run -c vitest.config.e2e.ts",
"test-build": "VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
"debug-serve": "VITE_DEBUG_SERVE=1 vitest run -c vitest.config.e2e.ts",
"debug-build": "VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 vitest run -c vitest.config.e2e.ts",
"typecheck": "vue-tsc --noEmit",
"build": "unbuild",
"commit": "cz"
Expand All @@ -16,9 +19,15 @@
"./plugin-example-one": {
"import": "./dist/plugin-example-one/index.mjs",
"types": "./dist/plugin-example-one/index.d.ts"
},
"./plugin-dynamic-import-retry": {
"import": "./dist/plugin-dynamic-import-retry/index.mjs",
"types": "./dist/plugin-dynamic-import-retry/index.d.ts"
}
},
"files": ["dist"],
"files": [
"dist"
],
"author": "Kong, Inc.",
"license": "Apache-2.0",
"devDependencies": {
Expand All @@ -27,10 +36,15 @@
"@digitalroute/cz-conventional-changelog-for-jira": "^8.0.1",
"@evilmartians/lefthook": "^1.10.1",
"@kong/eslint-config-kong-ui": "^1.2.2",
"@types/fs-extra": "^11.0.4",
"@vitest/ui": "^2.1.8",
"eslint": "^9.17.0",
"fs-extra": "^11.2.0",
"npm-run-all2": "^7.0.2",
"playwright-chromium": "^1.49.1",
"typescript": "^5.7.2",
"unbuild": "^3.2.0",
"vite": "^6.0.7",
"vitest": "^2.1.8",
"vue-tsc": "^2.2.0"
},
Expand All @@ -52,5 +66,13 @@
"jiraPrepend": "[",
"jiraAppend": "]"
}
},
"dependencies": {
"@rollup/pluginutils": "^5.1.4",
"acorn-walk": "^8.3.4",
"magic-string": "^0.30.17"
},
"peerDependencies": {
"vite": "^5.0.0 || ^6.0.0"
}
}
49 changes: 49 additions & 0 deletions playground/vitestGlobalSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os from 'node:os'
import path from 'node:path'
import fs from 'fs-extra'
import type { BrowserServer } from 'playwright-chromium'
import { chromium } from 'playwright-chromium'

const DIR = path.join(os.tmpdir(), 'vitest_playwright_global_setup')

let browserServer: BrowserServer | undefined

export async function setup(): Promise<void> {
browserServer = await chromium.launchServer({
headless: !process.env.VITE_DEBUG_SERVE,
args: process.env.CI
? ['--no-sandbox', '--disable-setuid-sandbox']
: undefined,
})

await fs.mkdirp(DIR)
await fs.writeFile(path.join(DIR, 'wsEndpoint'), browserServer.wsEndpoint())

const tempDir = path.resolve(__dirname, '../playground-temp')
await fs.ensureDir(tempDir)
await fs.emptyDir(tempDir)
await fs
.copy(path.resolve(__dirname, '../playground'), tempDir, {
dereference: false,
filter(file) {
file = file.replace(/\\/g, '/')
return !file.includes('__tests__') && !file.match(/dist(\/|$)/)
},
})
.catch(async (error) => {
if (error.code === 'EPERM' && error.syscall === 'symlink') {
throw new Error(
'Could not create symlinks. On Windows, consider activating Developer Mode to allow non-admin users to create symlinks by following the instructions at https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development.',
)
} else {
throw error
}
})
}

export async function teardown(): Promise<void> {
await browserServer?.close()
if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) {
fs.removeSync(path.resolve(__dirname, '../playground-temp'))
}
}
Loading

0 comments on commit 77c17e6

Please sign in to comment.