Skip to content

Commit

Permalink
fixup!: argument position (node quirk)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobJingleheimer committed Dec 22, 2024
1 parent 31526c1 commit 330818f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ jobs:
- name: Generate bundle & publish to codemod registry
run: >-
node
--experimental-strip=types
--no-warnings
--experimental-strip-types
./build/publish.mts
--recipes=${{steps.filter.outputs.codemods_files}}
--status=${{steps.filter.outputs.codemods}}
./build/publish.mts
7 changes: 4 additions & 3 deletions build/publish.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path';
import { argv, cwd, exit } from 'node:process';
import { argv, cwd } from 'node:process';
import { parseArgs } from 'node:util';

import { publish } from 'codemod';
Expand All @@ -11,6 +11,7 @@ const {
recipes,
status,
} = parseArgs({
allowPositionals: true,
args: argv,
options: {
recipes: { type: 'string' },
Expand All @@ -29,12 +30,12 @@ for (let r = n - 1; r > -1; r--) {
const recipeRelPath = recipeRelPaths[r];
const recipeAbsPath = path.join(rootPath, recipeRelPath);

publications[r] = bundle[r](recipeAbsPath)
publications[r] = bundle(recipeAbsPath)
.then(() => publish(path.join(recipeAbsPath, outfile)));
}

Promise.allSettled(publications)
.then(
() => console.log('Publishing complete'),
() => console.log('Publishing failed'),
() => console.error('Publishing failed'),
);
45 changes: 19 additions & 26 deletions build/publish.spec.mts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import assert from 'node:assert/strict';
import { execPath } from 'node:process';
import { cwd, argv } from 'node:process';
import {
before,
describe,
it,
mock,
} from 'node:test';

import { spawnPromisified } from './spawn-promisified.ts';


type Mock = ReturnType<typeof mock.fn>['mock'];

describe('Publishing', () => {
const cwd = '/test';
const CWD = cwd();
const outfile = 'out.js';
let mock__bundle: Mock;
let mock__publish: Mock;
let mock__consoleErr: Mock;
let mock__consoleLog: Mock;

before(async () => {
const bundle = mock.fn();
Expand All @@ -31,40 +32,32 @@ describe('Publishing', () => {
mock.module('./bundle.mts', {
namedExports: {
bundle,
outfile,
},
});
// mock.method(console, 'error');
// mock.method(console, 'log');
});

it('should', async () => {
mock__bundle.mockImplementationOnce(Promise.resolve);
mock__publish.mockImplementationOnce(Promise.resolve);
mock__bundle.mockImplementation(async () => { });
mock__publish.mockImplementation(() => { });

const { code, stderr, stdout } = await spawnPromisified(
execPath,
[
'--no-warnings',
'--experimental-strip-types',
'--recipes=("a" "b")',
'--status=true',
'./publish.mts',
],
{
cwd,
},
);
argv[2] = '--recipes=("a" "b")';
argv[3] = '--status';

assert.equal(stderr, '');
assert.equal(code, 0);
assert.match(stdout, /Publishing complete/);
await import('./publish.mts');

assert.deepEqual(mock__bundle.calls, [
{ arguments: [`${cwd}/a`] },
{ arguments: [`${cwd}/b`] },
{ arguments: [`${CWD}/a`] },
{ arguments: [`${CWD}/b`] },
]);

assert.deepEqual(mock__publish.calls, [
{ arguments: [`${cwd}/a`] },
{ arguments: [`${cwd}/b`] },
{ arguments: [`${CWD}/a`] },
{ arguments: [`${CWD}/b`] },
]);

assert.match(mock__consoleLog.calls[0].arguments[0], /Publishing complete/);
});
});

0 comments on commit 330818f

Please sign in to comment.