Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dynamic import retry plugin [KM-865] #2

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we tie the cache key here to a dynamic string that includes the playwright dependency version from package.json?

path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: It would be preferred to give the step an id, output via $GITHUB_OUTPUT, and then reference the step output below where needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


- 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe some additional playwright artifact paths will need to be added

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/plugin-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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: I'm not sure I understand the multiple test commands here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug-* are not necessary, removed

"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> {
adamdehaven marked this conversation as resolved.
Show resolved Hide resolved
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
Loading