Skip to content

Commit

Permalink
chore(repo): use latest version in e2e tests to avoid pnpm 7 issues (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed May 24, 2022
1 parent 0cf5269 commit 85485cc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
5 changes: 3 additions & 2 deletions e2e/add-nx-to-monorepo/src/add-nx-to-monorepo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
updateFile,
getPackageManagerCommand,
getSelectedPackageManager,
getPublishedVersion,
} from '@nrwl/e2e/utils';
import { Workspaces } from 'nx/src/config/workspaces';

Expand Down Expand Up @@ -33,7 +34,7 @@ describe('add-nx-to-monorepo', () => {

// Act
const output = runCommand(
`${packageManagerCommand} add-nx-to-monorepo@latest --nx-cloud false`
`${packageManagerCommand} add-nx-to-monorepo@${getPublishedVersion()} --nx-cloud false`
);
// Assert
expect(output).toContain('🎉 Done!');
Expand All @@ -58,7 +59,7 @@ describe('add-nx-to-monorepo', () => {

// Act
runCommand(
`${packageManagerCommand} add-nx-to-monorepo@latest --nx-cloud false`
`${packageManagerCommand} add-nx-to-monorepo@${getPublishedVersion()} --nx-cloud false`
);
const output = runCLI('build package-a');
// Assert
Expand Down
3 changes: 2 additions & 1 deletion e2e/cli/src/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
getPublishedVersion,
isNotWindows,
newProject,
readFile,
Expand Down Expand Up @@ -86,7 +87,7 @@ describe('Cli', () => {
expect(affectedHelp).toContain('Run target for affected projects');

const version = runCLI(`--version`);
expect(version).toContain('9999.0.2'); // stub value
expect(version).toContain(getPublishedVersion()); // stub value
}, 120000);
});

Expand Down
26 changes: 19 additions & 7 deletions e2e/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
joinPathFragments,
parseJson,
ProjectConfiguration,
readJsonFile,
WorkspaceJsonConfiguration,
} from '@nrwl/devkit';
import { angularCliVersion } from '@nrwl/workspace/src/utils/versions';
Expand Down Expand Up @@ -31,6 +32,16 @@ import treeKill = require('tree-kill');
import { Workspaces } from '../../packages/nx/src/config/workspaces';
import { PackageManager } from 'nx/src/utils/package-manager';

export function getPublishedVersion(): string {
process.env.PUBLISHED_VERSION =
process.env.PUBLISHED_VERSION ||
// read version of built nx package
readJsonFile(`./build/packages/nx/package.json`).version ||
// fallback to latest if built nx package is missing
'latest';
return process.env.PUBLISHED_VERSION;
}

export function detectPackageManager(dir: string = ''): PackageManager {
return existsSync(join(dir, 'yarn.lock'))
? 'yarn'
Expand Down Expand Up @@ -66,7 +77,6 @@ export const e2eCwd = `${e2eRoot}/${currentCli()}`;
ensureDirSync(e2eCwd);

let projName: string;
const publishedVersion = process.env.PUBLISHED_VERSION || `9999.0.2`;

export function uniq(prefix: string) {
return `${prefix}${Math.floor(Math.random() * 10000000)}`;
Expand Down Expand Up @@ -197,7 +207,9 @@ export function runCreatePlugin(

const pm = getPackageManagerCommand({ packageManager });

let command = `${pm.runUninstalledPackage} create-nx-plugin@latest ${name}`;
let command = `${
pm.runUninstalledPackage
} create-nx-plugin@${getPublishedVersion()} ${name}`;

if (pluginName) {
command += ` --pluginName=${pluginName}`;
Expand All @@ -224,7 +236,7 @@ export function runCreatePlugin(
export function packageInstall(
pkg: string,
projName?: string,
version = publishedVersion
version = getPublishedVersion()
) {
const cwd = projName ? `${e2eCwd}/${projName}` : tmpProjPath();
const pm = getPackageManagerCommand({ path: cwd });
Expand Down Expand Up @@ -478,7 +490,7 @@ export function runCLIAsync(
export function runNgAdd(
packageName: string,
command?: string,
version: string = publishedVersion,
version: string = getPublishedVersion(),
opts: RunCmdOpts = {
silenceError: false,
env: null,
Expand Down Expand Up @@ -805,7 +817,7 @@ export function getPackageManagerCommand({
npm: {
createWorkspace: `npx ${
+npmMajorVersion >= 7 ? '--yes' : ''
} create-nx-workspace@${publishedVersion}`,
} create-nx-workspace@${getPublishedVersion()}`,
run: (script: string, args: string) => `npm run ${script} -- ${args}`,
runNx: `npx nx`,
runNxSilent: `npx nx`,
Expand All @@ -815,7 +827,7 @@ export function getPackageManagerCommand({
},
yarn: {
// `yarn create nx-workspace` is failing due to wrong global path
createWorkspace: `yarn global add create-nx-workspace@${publishedVersion} && create-nx-workspace`,
createWorkspace: `yarn global add create-nx-workspace@${getPublishedVersion()} && create-nx-workspace`,
run: (script: string, args: string) => `yarn ${script} ${args}`,
runNx: `yarn nx`,
runNxSilent: `yarn --silent nx`,
Expand All @@ -825,7 +837,7 @@ export function getPackageManagerCommand({
},
// Pnpm 3.5+ adds nx to
pnpm: {
createWorkspace: `pnpm dlx create-nx-workspace@${publishedVersion}`,
createWorkspace: `pnpm dlx create-nx-workspace@${getPublishedVersion()}`,
run: (script: string, args: string) => `pnpm run ${script} -- ${args}`,
runNx: `pnpm exec nx`,
runNxSilent: `pnpm exec nx`,
Expand Down
3 changes: 1 addition & 2 deletions scripts/e2e-build-package-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { remove } from 'fs-extra';
import { existsSync } from 'fs';
import { stripIndent } from 'nx/src/utils/logger';

process.env.PUBLISHED_VERSION = process.env.PUBLISHED_VERSION || `9999.0.2`;
process.env.npm_config_registry = `http://localhost:4872`;
process.env.YARN_REGISTRY = process.env.npm_config_registry;

Expand Down Expand Up @@ -43,7 +42,7 @@ async function buildPackagePublishAndCleanPorts() {
}

async function updateVersionsAndPublishPackages() {
execSync(`yarn nx-release ${process.env.PUBLISHED_VERSION} --local`, {
execSync(`yarn nx-release --local`, {
stdio: 'inherit',
});
}
Expand Down

0 comments on commit 85485cc

Please sign in to comment.