Skip to content

Commit

Permalink
Improvements for runs on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Oct 23, 2024
1 parent bf8454d commit 58165cd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/pilet-build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { cliVersion, runTests, selectedBundler } from './utils';
runTests('pilet-build', ({ test, setup }) => {
setup(async (ctx) => {
await ctx.run(`npx --package piral-cli@${cliVersion} pilet new sample-piral@${cliVersion} --bundler none`);
await ctx.pause(2); // pauses for windows
await ctx.run(`npm i ${selectedBundler} --save-dev`);
await ctx.pause(1); // pauses for windows
await ctx.run(`npm i emojis-list@3.0.0`);
await ctx.pause(1); // pauses for windows
});

test(
Expand Down
6 changes: 6 additions & 0 deletions src/utils/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { exists, globFiles } from './io';
import { run as runFrom, runAsync as runAsyncFrom } from './process';
import { FileAssertions, FileMutations, TestContext } from './types';

export function pause(s: number) {
const ms = s * 1000;
return new Promise<void>(resolve => setTimeout(resolve, ms));
}

export function createTestContextFactory(dir: string) {
const refs: Record<string, string> = {};

Expand Down Expand Up @@ -109,6 +114,7 @@ export function createTestContextFactory(dir: string) {
return {
id,
root,
pause,
clean,
setRef,
getRef,
Expand Down
8 changes: 7 additions & 1 deletion src/utils/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ export function runAsync(cmd: string, cwd = process.cwd()): RunningProcess {
end() {
const promise = waitEnd();
cp.kill('SIGTERM');
cp.kill('SIGKILL');

try {
// might not work on Windows (EPERM)
cp.kill('SIGKILL');
} catch (err) {
console.warn(err);
}

if (!isWindows) {
// does not work on Windows
Expand Down
1 change: 1 addition & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface TestContext {
id: string;
clean(): Promise<void>;
run(cmd: string): Promise<string>;
pause(seconds: number): Promise<void>;
runAsync(cmd: string): RunningProcess;
setRef(id: string, file: string): void;
getRef(id: string): string;
Expand Down

0 comments on commit 58165cd

Please sign in to comment.