Skip to content

Effection v4 #365

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

Draft
wants to merge 61 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
15e49c8
upgrade a bunch of packages including effection
jbolda Jan 20, 2025
4fa40ec
convert files package to effection v4
jbolda Jan 20, 2025
f81828b
migrated changelog
jbolda Jan 20, 2025
0c16f72
migrate apply
jbolda Jan 20, 2025
2a91a7c
describe.skipIf
jbolda Jan 28, 2025
2ce6e4f
test scope experiments
jbolda Jan 29, 2025
c68ab98
Add test adapter based on effection contrib
cowboyd Feb 5, 2025
1d19e9e
swap to execa, compat tests
jbolda Feb 7, 2025
30c80aa
yield* higher packages
jbolda Feb 7, 2025
e98d4e9
yield* and call on command tests
jbolda Feb 7, 2025
f679ffd
prep higher command fn for new sh()
jbolda Feb 7, 2025
433dceb
handle for test suite functions with context
jbolda Feb 10, 2025
0e64956
update adapter to await
jbolda Feb 10, 2025
3081ba9
log out to make sure child is an AsyncIterable
cowboyd Feb 10, 2025
20375cb
pull out execa.pipe handler
jbolda Feb 11, 2025
b502d9d
passing command tests
jbolda Feb 11, 2025
4738875
passing assemble tests
jbolda Feb 11, 2025
e7b12a8
core covector tests passing
jbolda Mar 1, 2025
ed68ca8
clean up typescript config
jbolda Mar 4, 2025
668dbfb
fix typescript project references
jbolda Mar 4, 2025
30ccf4a
fix TS project references circular and all type errors
jbolda Mar 5, 2025
850ac21
fix assemble bumps
jbolda Mar 10, 2025
c403332
fix a bunch of snapshots
jbolda Mar 18, 2025
4e547b6
fix up action and tests
jbolda Mar 18, 2025
27e96a1
build action
jbolda Mar 18, 2025
ad68f83
adjust action file path ref
jbolda Mar 18, 2025
7df10aa
function to main
jbolda Mar 18, 2025
1643f72
swap back to tinyexec...
jbolda Mar 19, 2025
a12dda1
swap to esm for all packages
jbolda Mar 19, 2025
f7b153d
rip out lodash for better esm compat
jbolda Mar 19, 2025
29f0f3a
fix yargs hidebin
jbolda Mar 19, 2025
1066e42
action dist
jbolda Mar 19, 2025
077452e
resolve ts issues
jbolda Mar 20, 2025
046a751
regen action for mjs
jbolda Mar 20, 2025
7dc6781
swap off clone for validation
jbolda Mar 20, 2025
88e0eb2
throw on error of command, then catch
jbolda Mar 20, 2025
710dcbf
fix init and CLI tests
jbolda Mar 20, 2025
ee1045d
swap back to ncc, fix types through to action
jbolda Mar 21, 2025
75ea77a
fix tests
jbolda Mar 21, 2025
76d0985
rebuild action again
jbolda Mar 21, 2025
da6e79e
try copying and deleting wasm before running build
jbolda Mar 21, 2025
3cda500
try web build
jbolda Mar 21, 2025
35c401e
rollup is a failure
jbolda Mar 22, 2025
68bba1a
try with vite
jbolda Mar 22, 2025
1afb1da
try rollup with esbuild
jbolda Mar 24, 2025
c46a370
function call in main
jbolda Mar 24, 2025
9faca22
use wasm plugin for vitest
jbolda Mar 24, 2025
7d0c83a
wasm-pack module requires experimental, back to nodejs bundler
jbolda Mar 24, 2025
752c220
strip ansi for CLI tests in CI
jbolda Mar 24, 2025
4880570
upgrade effection to v4 alpha 7
jbolda Mar 24, 2025
397ce6c
try polyfilling the __dirname
jbolda Mar 24, 2025
52f335b
inject __dirname for cjs toml
jbolda Mar 24, 2025
0e4aeef
more direct inject
jbolda Mar 24, 2025
e9fce42
copy over wasm
jbolda Mar 25, 2025
a317095
cjs plugin, then shim
jbolda Mar 25, 2025
855139a
test e2e using built action to check toml
jbolda Mar 27, 2025
2dd0f6d
build action before test runs
jbolda Mar 27, 2025
3f8194f
set-output gets clipped in CI
jbolda Mar 27, 2025
8025407
commandFailure fix for windows
jbolda Mar 27, 2025
978a734
fixes some windows tests
jbolda Mar 30, 2025
f83e385
upgrade to effection v4 beta
jbolda Jul 20, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/run-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: volta-cli/action@v4
- run: npm ci --ignore-scripts
- run: npm run build
- run: npm run pkg -w action
- run: npm run build:action
- name: covector status
uses: ./packages/action
id: covector
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ jobs:
- uses: volta-cli/action@v4
- run: npm ci
- run: npm run build # covector CLI tests run built files
- run: npm run build:action
- run: npm test
72 changes: 72 additions & 0 deletions helpers/test-adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { Future, Operation, Scope } from "effection";
import { createScope } from "effection";

export interface TestOp {
(): Operation<void>;
}

export interface TestAdapter {
readonly parent?: TestAdapter;
readonly name: string;
readonly fullname: string;
readonly scope: Scope;
readonly lineage: Array<TestAdapter>;
readonly setups: TestOp[];
addSetup(op: TestOp): void;
runTest(body: TestOp): Future<void>;
destroy(): Future<void>;
}

export interface TestAdapterOptions {
name?: string;
parent?: TestAdapter;
}

const anonymousNames: Iterator<string, never> = (function* () {
let count = 1;
while (true) {
yield `anonymous test adapter ${count++}`;
}
})();

export function createTestAdapter(options: TestAdapterOptions): TestAdapter {
let setups: TestOp[] = [];
let { parent, name = anonymousNames.next().value } = options;

let [scope, destroy] = createScope(parent?.scope);

let adapter: TestAdapter = {
parent,
name,
scope,
setups,
get lineage() {
let lineage = [adapter];
for (let current = parent; current; current = current.parent) {
lineage.unshift(current);
}
return lineage;
},
get fullname() {
return adapter.lineage.map((adapter) => adapter.name).join(" > ");
},
addSetup(op) {
setups.push(op);
},
runTest(op) {
return scope.run(function* () {
let allSetups = adapter.lineage.reduce(
(all, adapter) => all.concat(adapter.setups),
[] as TestOp[]
);
for (let setup of allSetups) {
yield* setup();
}
yield* op();
});
},
destroy,
};

return adapter;
}
122 changes: 75 additions & 47 deletions helpers/test-scope.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
import { type Operation, run } from "effection";

export interface TestScope {
addSetup(op: () => Operation<void>): void;
runTest(op: () => Operation<void>): Promise<void>;
}

export function createTestScope(): TestScope {
let setup: (() => Operation<void>)[] = [];
return {
addSetup(op) {
setup.push(op);
},
runTest(op) {
return run(function* () {
for (let step of setup) {
yield step();
}
yield op();
});
},
};
}
import { type Operation } from "effection";
import { createTestAdapter, TestAdapter } from "./test-adapter";

import * as vitest from "vitest";

let scope: TestScope | undefined;

function describeWithScope(
name: string | Function,
factory?: vitest.SuiteFactory<{}>
): vitest.SuiteCollector<{}> {
return vitest.describe(name, () => {
vitest.beforeEach(() => {
if (!scope) {
scope = createTestScope();
}
factory?: vitest.SuiteFactory
): vitest.SuiteCollector {
return vitest.describe(name, (...args) => {
vitest.beforeAll((suite: any) => {
let parent = suite.suite?.adapter;
suite.adapter = createTestAdapter({ name: String(name), parent });
});

vitest.afterAll(async (suite: any) => {
await suite.adapter.destroy();
});

if (factory && typeof factory === "function") {
(<Function>factory)();
factory(...args);
}
});
}

describeWithScope.only = vitest.describe.only;
describeWithScope.only = function describeWithScope(
name: string | Function,
factory?: vitest.SuiteFactory
): vitest.SuiteCollector {
return vitest.describe.only(name, (...args) => {
vitest.beforeAll((suite: any) => {
let parent = suite.suite?.adapter;
suite.adapter = createTestAdapter({ name: String(name), parent });
});

vitest.afterAll(async (suite: any) => {
await suite.adapter.destroy();
});

if (factory && typeof factory === "function") {
factory(...args);
}
});
};
describeWithScope.skip = vitest.describe.skip;
describeWithScope.skipIf = vitest.describe.skipIf;
describeWithScope.skipIf = (condition: any) =>
condition ? describeWithScope.skip : describeWithScope;
describeWithScope.runIf = (condition: any) =>
condition ? describeWithScope : describeWithScope.skip;

export const describe = <typeof vitest.describe>(<unknown>describeWithScope);

export function beforeEach(op: () => Operation<void>): void {
vitest.beforeEach(() => scope!.addSetup(op));
vitest.beforeEach((context: any) => {
context.task.suite.adapter.addSetup(op);
});
}

export function it(
Expand All @@ -58,9 +62,18 @@ export function it(
timeout?: number
): void {
if (op) {
return vitest.it(desc, async () => scope?.runTest(op), timeout);
return vitest.it(
desc,
async (context) => {
if (!context.task.suite?.adapter)
throw new Error("missing test adapter");
let adapter: TestAdapter = context.task.suite.adapter;
return adapter.runTest(op);
},
timeout
);
} else {
return vitest.it.skip(desc, () => {});
return vitest.it.todo(desc);
}
}

Expand All @@ -70,19 +83,34 @@ it.only = function only(
timeout?: number
): void {
if (op) {
return vitest.it.only(desc, async () => scope!.runTest(op), timeout);
return vitest.it.only(
desc,
async (context) => {
if (!context.task.suite?.adapter)
throw new Error("missing test adapter");
let adapter: TestAdapter = context.task.suite.adapter;
return adapter.runTest(op);
},
timeout
);
} else {
return vitest.it.skip(desc, () => {});
}
};

export function captureError<T>(op: Operation<T>): Operation<T | Error> {
return function* () {
try {
yield op;
} catch (error) {
return error;
}
it.skip = function skip(
desc: string,
op?: () => Operation<void>,
timeout?: number
): void {
return vitest.it.skip(desc, () => {});
};

export function* captureError<T>(op: Operation<T>): Operation<Error> {
try {
yield* op;
throw new Error("expected operation to throw an error, but it did not!");
};
} catch (error) {
return error;
}
}
Loading
Loading