From 3e78e328c116e32e542af87e85a85f3dcc19d0ff Mon Sep 17 00:00:00 2001 From: vscaiceanu-1a <86055112+vscaiceanu-1a@users.noreply.github.com> Date: Tue, 16 Jan 2024 16:46:10 +0100 Subject: [PATCH] feat(it-tests): test schematics with yarn 1 --- .github/workflows/it-tests.yml | 2 +- packages/@o3r/test-helpers/src/prepare-test-env.ts | 7 +++---- .../@o3r/test-helpers/src/utilities/package-manager.ts | 9 +++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/it-tests.yml b/.github/workflows/it-tests.yml index f8a6beb075..35b1eb92c4 100644 --- a/.github/workflows/it-tests.yml +++ b/.github/workflows/it-tests.yml @@ -51,7 +51,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - packageManager: [yarn, npm] + packageManager: [yarn, npm, yarn1] testEnvironment: [o3r-project-with-app] runs-on: ${{ matrix.os }} env: diff --git a/packages/@o3r/test-helpers/src/prepare-test-env.ts b/packages/@o3r/test-helpers/src/prepare-test-env.ts index e67e72424d..9c39e9a98d 100644 --- a/packages/@o3r/test-helpers/src/prepare-test-env.ts +++ b/packages/@o3r/test-helpers/src/prepare-test-env.ts @@ -3,7 +3,7 @@ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statS import * as path from 'node:path'; import type { PackageJson } from 'type-fest'; import { createTestEnvironmentBlank } from './test-environments/create-test-environment-blank'; -import { createWithLock, getPackageManager, type Logger, packageManagerInstall, setPackagerManagerConfig, setupGit } from './utilities/index'; +import { createWithLock, getPackageManager, type Logger, packageManagerInstall, setPackagerManagerConfig, setupGit, isYarn1, YARN_1_LATEST_VERSION } from './utilities/index'; import { createTestEnvironmentOtterProjectWithApp } from './test-environments/create-test-environment-otter-project'; import { O3rCliError } from '@o3r/schematics'; @@ -19,8 +19,7 @@ export type PrepareTestEnvType = 'blank' | 'o3r-project-with-app'; /** * Retrieve the version used by yarn and setup at root level - * @param rootFolderPath: path to the folder where to take the configuration from - * @param rootFolderPath + * @param rootFolderPath path to the folder where to take the configuration from */ export function getYarnVersionFromRoot(rootFolderPath: string) { const o3rPackageJson: PackageJson & { generatorDependencies?: Record } = @@ -53,7 +52,7 @@ export async function prepareTestEnv(folderName: string, options?: PrepareTestEn const cacheFolderPath = path.resolve(globalFolderPath, 'cache'); JSON.parse(readFileSync(path.join(rootFolderPath, 'packages', '@o3r', 'core', 'package.json')).toString()); - const yarnVersion: string = yarnVersionParam || getYarnVersionFromRoot(rootFolderPath); + const yarnVersion: string = yarnVersionParam || (isYarn1() && YARN_1_LATEST_VERSION) || getYarnVersionFromRoot(rootFolderPath); const execAppOptions: ExecSyncOptions = { cwd: workspacePath, stdio: 'inherit', diff --git a/packages/@o3r/test-helpers/src/utilities/package-manager.ts b/packages/@o3r/test-helpers/src/utilities/package-manager.ts index 7890b91a44..96fcbcca51 100644 --- a/packages/@o3r/test-helpers/src/utilities/package-manager.ts +++ b/packages/@o3r/test-helpers/src/utilities/package-manager.ts @@ -49,6 +49,15 @@ export function getPackageManager() { 'yarn'; } +export const YARN_1_LATEST_VERSION = '1.22.19'; + +/** + * + */ +export function isYarn1() { + return process.env.ENFORCED_PACKAGE_MANAGER === 'yarn1'; +} + /** * Need to add additional dashes when running command like exec on npm * Convert `npm exec test --param` to `npm exec test -- --param`