Skip to content

Commit

Permalink
chore: setup basic test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Apr 22, 2024
1 parent f6e16b5 commit 1d2ed6d
Show file tree
Hide file tree
Showing 51 changed files with 5,418 additions and 261 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/test-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Test (Ubuntu)

# Controls when the action will run.
on:
# Triggers the workflow on pull request events but only for the main branch
pull_request:
branches: [main]

push:
branches: [main]

merge_group:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# ======== ut ========
ut-mac:
# run ut in MacOS, as SWC cases will fail in Ubuntu CI
runs-on: macos-14
strategy:
matrix:
node-version: [18.x]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 10

- name: Install Pnpm
run: corepack enable

- uses: dorny/paths-filter@v3
id: changes
with:
predicate-quantifier: 'every'
filters: |
changed:
- "!**/*.md"
- "!**/*.mdx"
- name: Setup Node.js ${{ matrix.node-version }}
if: steps.changes.outputs.changed == 'true'
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install Dependencies
if: steps.changes.outputs.changed == 'true'
run: pnpm install

- name: Unit Test
if: steps.changes.outputs.changed == 'true'
run: pnpm run test:unit

# ======== e2e ========
e2e-ubuntu:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 10

- name: Install Pnpm
run: corepack enable

- uses: dorny/paths-filter@v3
id: changes
with:
predicate-quantifier: 'every'
filters: |
changed:
- "!**/*.md"
- "!**/*.mdx"
- name: Setup Node.js ${{ matrix.node-version }}
if: steps.changes.outputs.changed == 'true'
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install Dependencies
if: steps.changes.outputs.changed == 'true'
run: pnpm install && cd ./e2e && pnpx playwright install

- name: E2E Test
if: steps.changes.outputs.changed == 'true'
run: |
pnpm run test:artifact
pnpm run test:e2e
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
registry = 'https://registry.npmjs.org/'
strict-peer-dependencies=false
hoist-patterns[]=[]
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.20.2
v18.20.2
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["biomejs.biome"]
}
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"search.useIgnoreFiles": true,
"search.exclude": {
"**/.git": true,
"**/dist": true,
"**/coverage": true,
"**/compiled": true,
"**/doc_build": true,
"**/node_modules": true,
"**/tsconfig.tsbuildinfo": true
},
"files.exclude": {
"**/.DS_Store": true
},
"mdx.validate.validateFileLinks": "ignore",
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit"
}
}
54 changes: 54 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
"organizeImports": {
"enabled": true,
"include": [
"./**/*.js",
"./**/*.jsx",
"./**/*.ts",
"./**/*.tsx",
"./**/*.mjs",
"./**/*.cjs"
]
},
"vcs": {
"enabled": true,
"defaultBranch": "main",
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": true
},
"formatter": {
"indentStyle": "space"
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"semicolons": "asNeeded"
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noNonNullAssertion": "off",
"useFilenamingConvention": {
"level": "error",
"options": {
"filenameCases": ["camelCase", "PascalCase", "export"]
}
}
},
"suspicious": {
"noExplicitAny": "off",
"noConfusingVoidType": "off"
},
"performance": {
"noDelete": "off"
}
}
}
}
5 changes: 5 additions & 0 deletions e2e/cases/define/index.pw.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, test } from '@playwright/test'

test('todo', async () => {
expect(1).toBe(1)
})
23 changes: 23 additions & 0 deletions e2e/cases/define/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { build } from '@rslib/core'
import { expect, test } from 'vitest'
import { globContentJSON } from '#helper'

test.fails('define', async () => {
// @ts-expect-error follow conventional
delete process.env.NODE_ENV

const rslibConfig = {
root: __dirname,
entry: './js/src/index.js',
outDir: 'dist',
}

const instance = await build(rslibConfig)
const results = await globContentJSON(instance.context.distPath, {
absolute: true,
ignore: ['/**/*.map'],
})

const entryJs = Object.keys(results).find((file) => file.endsWith('.js'))
expect(results[entryJs!]).not.toContain('console.info(VERSION)')
})
1 change: 1 addition & 0 deletions e2e/cases/define/js/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.info(VERSION)
21 changes: 21 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@rslib/e2e",
"private": true,
"type": "module",
"scripts": {
"test": "playwright test"
},
"imports": {
"#helper": "./scripts/helper.ts"
},
"devDependencies": {
"@playwright/test": "1.43.1",
"@rslib/core": "workspace:*",
"@rslib/tsconfig": "workspace:*",
"@types/fs-extra": "^11.0.4",
"@types/node": "16.x",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"typescript": "^5.4.5"
}
}
6 changes: 6 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from '@playwright/test'

export default defineConfig({
// Playwright test files with `.pw.` to distinguish from Vitest test files
testMatch: /.*pw.(test|spec).(js|ts|mjs)/,
})
33 changes: 33 additions & 0 deletions e2e/scripts/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { platform } from 'node:os'
import { join } from 'node:path'
import fg, {
type Options as GlobOptions,
convertPathToPattern,
} from 'fast-glob'
import fse from 'fs-extra'

export const getFiles = async (pattern: string) => {}

// fast-glob only accepts posix path
// https://github.com/mrmlnc/fast-glob#convertpathtopatternpath
const convertPath = (path: string) => {
if (platform() === 'win32') {
return convertPathToPattern(path)
}
return path
}

export const globContentJSON = async (path: string, options?: GlobOptions) => {
const files = await fg(convertPath(join(path, '**/*')), options)
const ret: Record<string, string> = {}

await Promise.all(
files.map((file) =>
fse.readFile(file, 'utf-8').then((content) => {
ret[file] = content
}),
),
)

return ret
}
1 change: 1 addition & 0 deletions e2e/scripts/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import {} from '@rslib/core'
8 changes: 8 additions & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@rslib/tsconfig/base",
"compilerOptions": {
"noEmit": true
},
"include": ["cases", "playwright.config.ts", "cases/**/*.test.ts", "scripts"],
"exclude": ["**/node_modules", "**/.*/"]
}
28 changes: 23 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
{
"private": true,
"name": "rslib-monorepo",
"scripts": {},
"packageManager": "[email protected]",
"packageManager": "[email protected]",
"engines": {
"node": ">=16.18.1"
},
"scripts": {
"build": "pnpm -r --filter='./packages/*' run build",
"prepare": "pnpm run build && simple-git-hooks",
"test:unit": "vitest run --project unit",
"test:artifact": "vitest run --project artifact",
"test:e2e": "cd e2e && pnpm run test",
"check-dependency-version": "check-dependency-version-consistency .",
"lint": "biome check . --diagnostic-level=warn"
},
"simple-git-hooks": {
"pre-commit": "npx nano-staged"
},
"nano-staged": {
"*.{md,mdx,json,css,less,scss}": "prettier --write",
"*.{js,jsx,ts,tsx,mjs,cjs}": [
"biome check --apply --formatter-enabled=false --linter-enabled=false",
"prettier --write"
]
],
"package.json": "pnpm run check-dependency-version"
},
"devDependencies": {
"prettier": "^3.2.4",
"@biomejs/biome": "^1.7.0",
"@modern-js/module-tools": "^2.48.6",
"check-dependency-version-consistency": "^4.1.0",
"cross-env": "^7.0.3",
"nano-staged": "^0.8.0",
"simple-git-hooks": "^2.10.0"
"prettier": "^3.2.4",
"simple-git-hooks": "^2.10.0",
"vitest": "^1.5.0"
}
}
8 changes: 8 additions & 0 deletions packages/core/bin/rslib.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node

async function main() {
const { runCli } = require('../dist/cli')
runCli()
}

main()
14 changes: 14 additions & 0 deletions packages/core/modern.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig, moduleTools } from '@modern-js/module-tools'

export default defineConfig({
plugins: [moduleTools()],
buildConfig: [
{
input: ['src'],
buildType: 'bundleless',
format: 'cjs',
autoExtension: true,
target: 'es2020',
},
],
})
28 changes: 28 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@rslib/core",
"type": "commonjs",
"bin": {
"rslib": "./bin/rslib.js"
},
"main": "./dist/main.js",
"types": "./dist/main.d.ts",
"exports": {
".": {
"types": "./dist/main.d.ts",
"default": "./dist/main.js"
}
},
"scripts": {
"build": "modern build",
"dev": "modern build --watch"
},
"dependencies": {
"@rsbuild/core": "0.6.2",
"@rsbuild/shared": "0.6.2",
"commander": "^12.0.0"
},
"devDependencies": {
"@rslib/tsconfig": "workspace:*",
"typescript": "^5.4.5"
}
}
Loading

0 comments on commit 1d2ed6d

Please sign in to comment.