-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit f2da45f
Showing
13 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
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,37 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/[email protected] | ||
with: | ||
persist-credentials: false | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: "18.x" | ||
cache: "npm" | ||
|
||
- name: Install | ||
run: env NODE_ENV=development npm install --prefer-offline --no-audit | ||
- name: Test | ||
run: npm run typecheck && npm run test | ||
|
||
- name: Build | ||
run: env NODE_ENV=production npm run build | ||
- run: jq -s 'add' package.json package-publish.json > package-final.json && rm -rf package.json && mv package-final.json package.json | ||
|
||
- id: Publish | ||
uses: JS-DevTools/npm-publish@v1 | ||
with: | ||
registry: "https://registry.npmjs.org/" | ||
token: ${{ secrets.NPM_TOKEN }} | ||
access: "public" | ||
check-version: true | ||
- if: steps.publish.outputs.type != 'none' | ||
run: | | ||
echo "Version changed: ${{ steps.publish.outputs.old-version }} => ${{ steps.publish.outputs.version }}" |
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,4 @@ | ||
node_modules | ||
.vscode | ||
.DS_Store | ||
dist |
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,7 @@ | ||
|
||
.SHELL := /usr/bin/bash | ||
|
||
.PHONY: build | ||
build: | ||
npx tsc --resolveJsonModule -p ./tsconfig.json --outDir ./dist --emitDeclarationOnly --declaration | ||
node esbuild.mjs |
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,22 @@ | ||
import * as esbuild from "esbuild"; | ||
|
||
(async () => { | ||
await esbuild.build({ | ||
entryPoints: ["src/index.ts"], // Specify your entry point(s) here | ||
outfile: "dist/index.js", // Specify the output file here | ||
bundle: true, | ||
packages: "external", | ||
target: "es2022", | ||
format: "esm", | ||
sourcemap: false, | ||
minify: true, | ||
plugins: [ | ||
// sassPlugin({ | ||
// type: "style", | ||
// transform: postcssModules({ | ||
// // ...put here the options for postcss-modules: https://github.com/madyankin/postcss-modules | ||
// }), | ||
// }), | ||
], | ||
}); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js" | ||
} | ||
} | ||
} |
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,38 @@ | ||
{ | ||
"name": "attorneyjs", | ||
"version": "0.8.32", | ||
"author": "Abhishiv Saxena<[email protected]>", | ||
"license": "MIT", | ||
"description": "Ultralean Test runner for browser and node", | ||
"keywords": [], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/abhishiv/attorney" | ||
}, | ||
"files": [ | ||
"./dist" | ||
], | ||
"devDependencies": { | ||
"esbuild": "^0.21.5", | ||
"typescript": "^5.2.2", | ||
"vitest": "^2.0.5" | ||
}, | ||
"scripts": { | ||
"build": "make build", | ||
"test": "npx vitest --run --passWithNoTests", | ||
"coverage": "vitest run --coverage --run --passWithNoTests", | ||
"typecheck": "npx tsc --noEmit" | ||
}, | ||
"main": "./src/index.ts", | ||
"exports": { | ||
".": { | ||
"import": "./src/index.ts" | ||
} | ||
}, | ||
"dependencies": { | ||
"buckwheat": "^1.1.2" | ||
}, | ||
"peerDependencies": { | ||
"alfama": "*" | ||
} | ||
} |
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,16 @@ | ||
import { describe, runSuite, printTap } from "./index"; | ||
|
||
const suite = describe("My first test suite", ({ test }) => { | ||
test("my test1", ({ expect }) => { | ||
expect(4).toBe(4); | ||
}); | ||
|
||
test("my test2", ({ expect }) => { | ||
expect(4).toBe(4); | ||
}); | ||
}); | ||
|
||
runSuite(suite).then((results) => { | ||
// console.log(results); | ||
console.log(printTap(results)); | ||
}); |
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,51 @@ | ||
import { | ||
Suite, | ||
SuiteMeta, | ||
SuiteHandler, | ||
SuiteAttrs, | ||
TestMeta, | ||
TestHandler, | ||
Results, | ||
} from "./types"; | ||
import { expect } from "buckwheat"; | ||
|
||
export * from "./types/index"; | ||
export * from "./tap"; | ||
|
||
export const describe = (meta: string | SuiteMeta, fn: SuiteHandler) => { | ||
const suite: Suite = { | ||
type: "Suite", | ||
meta: typeof meta === "string" ? { name: meta } : meta, | ||
tests: [], | ||
}; | ||
const attrs: SuiteAttrs = { | ||
test: (name: string | TestMeta, fn: TestHandler) => { | ||
suite.tests.push({ | ||
type: "Test", | ||
meta: typeof name === "string" ? { name } : name, | ||
fn: fn, | ||
}); | ||
}, | ||
}; | ||
fn(attrs); | ||
return suite; | ||
}; | ||
|
||
export async function runSuite(suite: Suite) { | ||
const results: Results = []; | ||
suite.tests.forEach(async (test, index) => { | ||
try { | ||
const fn = test.fn({ expect }); | ||
const result = await Promise.resolve(fn); | ||
results.push({ index, test, result, type: "passed" }); | ||
} catch (e) { | ||
results.push({ | ||
index, | ||
test, | ||
type: "failed", | ||
error: e as any, | ||
}); | ||
} | ||
}); | ||
return results; | ||
} |
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,31 @@ | ||
import { Results } from "./types/index"; | ||
|
||
export function printTap(arg: Results) { | ||
const results = arg; | ||
const tapOutput: string[] = []; | ||
|
||
// Pushing the test plan (total number of tests) into the array | ||
tapOutput.push(`1..${results.length}`); | ||
|
||
// Iterating through each test result and pushing TAP lines into the array | ||
results.forEach((result, i) => { | ||
if (result.type === "passed") { | ||
tapOutput.push(`ok ${result.index} - ${result.test.meta.name}`); | ||
} else { | ||
tapOutput.push(`not ok ${result.index} - ${result.test.meta.name}`); | ||
tapOutput.push(` ---`); | ||
tapOutput.push(` name: ${result.error.name}`); | ||
tapOutput.push(` operator: error`); | ||
if (result.error instanceof Error) { | ||
tapOutput.push(` message: ${result.error.message}`); | ||
tapOutput.push(` stack: ${result.error.stack}`); | ||
} else { | ||
tapOutput.push(` actual: ${result.error.actual}`); | ||
tapOutput.push(` expected: ${result.error.expected}`); | ||
} | ||
tapOutput.push(` ...`); | ||
} | ||
}); | ||
|
||
return tapOutput.join("\n"); | ||
} |
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,29 @@ | ||
import { expect } from "buckwheat"; | ||
|
||
export type SuiteAttrs = { test: TestDefinition }; | ||
export type SuiteHandler = (attrs: SuiteAttrs) => void; | ||
|
||
export type TestAttrs = { expect: typeof expect }; | ||
export type TestHandler = (attrs: TestAttrs) => void; | ||
|
||
export type SuiteMeta = { name: string }; | ||
export type TestMeta = { name: string }; | ||
|
||
export type TestDefinition = (name: string | TestMeta, fn: TestHandler) => void; | ||
|
||
export type Test = { type: "Test"; meta: TestMeta; fn: TestHandler }; | ||
export type Suite = { type: "Suite"; meta: SuiteMeta; tests: Test[] }; | ||
|
||
export type PassedResult = { | ||
index: number; | ||
type: "passed"; | ||
test: Test; | ||
result: any; | ||
}; | ||
export type FailedResult = { | ||
index: number; | ||
type: "failed"; | ||
test: Test; | ||
error: { name: string; actual: any; expected: any } | Error; | ||
}; | ||
export type Results = (PassedResult | FailedResult)[]; |
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,21 @@ | ||
{ | ||
"ts-node": { | ||
"compilerOptions": { | ||
"module": "commonjs" | ||
} | ||
}, | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"strict": true, | ||
"jsx": "react", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"esModuleInterop": true, | ||
"lib": ["ESNext", "DOM"], | ||
"skipLibCheck": true | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] | ||
} |
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,7 @@ | ||
import { defineConfig } from "vite"; | ||
|
||
export default defineConfig({ | ||
build: { | ||
target: "esnext", | ||
}, | ||
}); |