-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
3,614 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -7,3 +7,45 @@ on: | |
jobs: | ||
call-rust-build: | ||
uses: ./.github/workflows/plugin-build.yaml | ||
examples-test: | ||
name: Examples Test | ||
runs-on: ${{ matrix.settings.os }} | ||
needs: [call-rust-build] | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
settings: | ||
- os: ubuntu-latest | ||
abi: linux-x64-gnu | ||
- os: macos-latest | ||
abi: darwin-arm64 | ||
- os: macos-13 | ||
abi: darwin-x64 | ||
- os: windows-latest | ||
abi: win32-x64-msvc | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v3 | ||
- name: Setup Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
path: /tmp/artifacts | ||
- name: Move Artifacts | ||
run: | | ||
for abi in linux-x64-gnu linux-x64-musl darwin-x64 win32-x64-msvc linux-arm64-musl linux-arm64-gnu darwin-arm64 win32-ia32-msvc win32-arm64-msvc | ||
do | ||
for package in dsv react-components virtual yaml strip image url icons | ||
do | ||
folder_path="/tmp/artifacts/${{github.sha}}-${abi}-${package}" | ||
if [ -d "${folder_path}"] && [ -n "$(ls -A $folder_path)"]; then | ||
mv /tmp/artifacts/${{ github.sha }}-${abi}-${package}/* ./packages/${package}/npm/${abi} | ||
fi | ||
done | ||
done | ||
- name: Install Dependencies | ||
run: npm install -g [email protected] && pnpm i --frozen-lockfile | ||
- name: E2E Test Examples - ${{ matrix.settings.abi }} | ||
run: npm run test-e2e |
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
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,94 @@ | ||
export type SimpleUnwrapArray<T> = T extends ReadonlyArray<infer P> ? P : T; | ||
|
||
export function logger(msg: any, { title = 'FARM INFO', color = 'green' } = {}) { | ||
const COLOR_CODE = [ | ||
'black', | ||
'red', | ||
'green', | ||
'yellow', | ||
'blue', | ||
'magenta', | ||
'cyan', | ||
'white', | ||
].indexOf(color); | ||
if (COLOR_CODE >= 0) { | ||
const TITLE_STR = title ? `\x1b[4${COLOR_CODE};30m ${title} \x1b[0m ` : ''; | ||
console.log(`${TITLE_STR}\x1b[3${COLOR_CODE}m${msg}\x1b[;0m`); | ||
} else { | ||
console.log(title ? `${title} ${msg}` : msg); | ||
} | ||
} | ||
|
||
export interface Deferred<T = any> { | ||
resolve: (result: T) => void; | ||
reject: (reason: any) => void; | ||
promise: Promise<T>; | ||
} | ||
|
||
export const createDeferred = <T = any>(silent?: boolean) => { | ||
const deferred = {} as Deferred<T>; | ||
|
||
deferred.promise = new Promise<T>((resolve, reject) => { | ||
deferred.resolve = resolve; | ||
deferred.reject = reject; | ||
}); | ||
|
||
if (silent) { | ||
deferred.promise.catch(() => { }); | ||
} | ||
|
||
return deferred; | ||
}; | ||
|
||
|
||
export const concurrentify = <F extends (...args: any) => Promise<any>>(maxConcurrent: number, fn: F) => { | ||
const queue = [] as { | ||
deferred: Deferred; | ||
args: any; | ||
ctx: any; | ||
}[]; | ||
|
||
let concurrent = 0; | ||
|
||
function next() { | ||
concurrent -= 1; | ||
if (queue.length > 0) { | ||
const { ctx, deferred, args } = queue.shift()!; | ||
try { | ||
// eslint-disable-next-line no-use-before-define | ||
newFn.apply(ctx, args).then(deferred.resolve, deferred.reject); | ||
} catch (e) { | ||
deferred.reject(e); | ||
} | ||
} | ||
} | ||
|
||
function newFn(this: any) { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
const ctx = this; | ||
const args = arguments as any; | ||
|
||
if (concurrent >= maxConcurrent) { | ||
const deferred = createDeferred(); | ||
queue.push({ | ||
deferred, | ||
ctx, | ||
args, | ||
}); | ||
return deferred.promise; | ||
} | ||
|
||
concurrent += 1; | ||
|
||
return fn.apply(ctx, args).finally(next); | ||
} | ||
|
||
return newFn as F; | ||
}; | ||
|
||
export const concurrentMap = < | ||
Arr extends readonly unknown[], | ||
F extends (item: SimpleUnwrapArray<Arr>, index: number, arr: Arr) => Promise<any>, | ||
>(arr: Arr, maxConcurrent: number, cb: F) => arr.map( | ||
concurrentify(maxConcurrent, cb) as any, | ||
) as ReturnType<F>[]; |
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 type { GlobalSetupContext } from 'vitest/node'; | ||
import { chromium } from 'playwright-chromium'; | ||
import type { BrowserServer } from 'playwright-chromium'; | ||
import { createServer, Server } from 'http'; | ||
|
||
let browserServer: BrowserServer | undefined; | ||
let client: Server | undefined; | ||
|
||
const buffer = new SharedArrayBuffer(2); | ||
const u16 = new Uint16Array(buffer); | ||
|
||
function addPort() { | ||
return Atomics.add(u16, 0, 10); | ||
} | ||
|
||
function setPort(port: number) { | ||
return Atomics.store(u16, 0, port); | ||
} | ||
|
||
setPort(9100); | ||
|
||
export async function setup({ provide }: GlobalSetupContext): Promise<void> { | ||
browserServer = await chromium.launchServer({ | ||
headless: true | ||
}); | ||
|
||
client = createServer((req, res) => { | ||
if (req.url!.startsWith('/port')) { | ||
res.end(addPort().toString()); | ||
return; | ||
} | ||
// not found path | ||
res.statusCode = 404; | ||
res.end(); | ||
}); | ||
|
||
client.listen(12306); | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
provide('wsEndpoint', browserServer.wsEndpoint()); | ||
} | ||
|
||
export async function teardown(): Promise<void> { | ||
await browserServer?.close(); | ||
await new Promise((resolve, reject) => { | ||
client!.close((err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(undefined); | ||
} | ||
}); | ||
}); | ||
} |
Oops, something went wrong.