Skip to content

Commit

Permalink
WIP add yarnBerry to test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
appsforartists committed Nov 7, 2023
1 parent 47c83cb commit e321920
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 19 deletions.
53 changes: 49 additions & 4 deletions src/test/cli-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import * as assert from 'uvu/assert';
import {suite} from 'uvu';
import {rigTest} from './util/rig-test.js';
import {WireitTestRig} from './util/test-rig.js';
import {Options} from '../cli-options.js';
import {Agent, Options} from '../cli-options.js';
import {Result} from '../error.js';
import {IS_WINDOWS} from '../util/windows.js';

const test = suite<object>();

Expand Down Expand Up @@ -39,7 +40,38 @@ async function getOptionsResult(
},
},
});
env = {...env, WIREIT_DEBUG_LOG_FILE: ''};

if (command.startsWith('yarnBerry')) {
await rig.write({
'yarn.lock': `# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!
__metadata:
version: 8
cacheKey: 10c0
"root-workspace-0b6124@workspace:.":
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
languageName: unknown
linkType: soft
`,
});
await rig.write({
'.yarnrc.yml': 'nodeLinker: node-modules',
});
}

const PATH_SEPARATOR = IS_WINDOWS ? `;` : `:`;

env = {
...env,
WIREIT_DEBUG_LOG_FILE: '',
PATH: `${env?.PATH ?? process.env.PATH}${PATH_SEPARATOR}${
rig.temp
}/node_modules/.bin`,
};

assert.equal((await rig.exec(command, {env}).exit).code, 0);
return JSON.parse(await rig.read('options.json')) as Result<Options>;
}
Expand Down Expand Up @@ -67,8 +99,8 @@ async function assertOptions(
});
}

for (const command of ['npm', 'yarn', 'pnpm'] as const) {
const agent = command === 'yarn' ? 'yarnClassic' : command;
for (const command of ['npm', 'yarn', 'pnpm', 'yarnBerry'] as const) {
const agent: Agent = command === 'yarn' ? 'yarnClassic' : command;
// eslint-disable-next-line @typescript-eslint/unbound-method
const skipIfYarn = command === 'yarn' ? test.skip : test;
// eslint-disable-next-line @typescript-eslint/unbound-method
Expand All @@ -87,6 +119,19 @@ for (const command of ['npm', 'yarn', 'pnpm'] as const) {
}),
);

test(
`${command} run main`,
rigTest(async ({rig}) => {
await assertOptions(rig, `${command} run main`, {
agent,
script: {
packageDir: rig.temp,
name: 'main',
},
});
}),
);

test(
`${command} test`,
rigTest(async ({rig}) => {
Expand Down
42 changes: 27 additions & 15 deletions src/test/util/test-rig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,34 @@ export class WireitTestRig
*/
override async setup() {
await super.setup();
const absWireitBinaryPath = pathlib.resolve(repoRoot, 'bin', 'wireit.js');
const absWireitTempInstallPath = pathlib.resolve(
this.temp,
'node_modules',
'.bin',
'wireit',

await Promise.all(
[
['wireit', ['bin', 'wireit.js']] as const,
[
'yarnBerry',
['third_party', '.yarn', 'releases', 'yarn-4.0.1.cjs'],
] as const,
].map(async ([name, pathParts]) => {
const binaryPath = pathlib.resolve(repoRoot, ...pathParts);
const tempInstallPath = pathlib.resolve(
this.temp,
'node_modules',
'.bin',
name,
);

if (IS_WINDOWS) {
// Npm install works differently on Windows, since it won't recognize a
// shebang like "#!/usr/bin/env node". Npm instead uses the cmd-shim
// package to generate Windows shell wrappers for each binary, so we do
// that here too.
await cmdShim(binaryPath, tempInstallPath);
} else {
await this.symlink(binaryPath, tempInstallPath, 'file');
}
}),
);
if (IS_WINDOWS) {
// Npm install works differently on Windows, since it won't recognize a
// shebang like "#!/usr/bin/env node". Npm instead uses the cmd-shim
// package to generate Windows shell wrappers for each binary, so we do
// that here too.
await cmdShim(absWireitBinaryPath, absWireitTempInstallPath);
} else {
await this.symlink(absWireitBinaryPath, absWireitTempInstallPath, 'file');
}
}

/**
Expand Down

0 comments on commit e321920

Please sign in to comment.