Skip to content

Commit

Permalink
feat(it-tests): test schematics with yarn 1
Browse files Browse the repository at this point in the history
  • Loading branch information
vscaiceanu-1a committed Jan 22, 2024
1 parent 0536b3c commit 48b6dff
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/it-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
packageManager: [yarn, npm]
packageManager: [yarn, npm, yarn1]
exclude:
- os: windows-latest
packageManager: yarn
Expand Down
2 changes: 1 addition & 1 deletion packages/@o3r/analytics/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('new otter application with analytics', () => {
addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();
expect(() => packageManagerRun('build', { ...execAppOptions, cwd: appFolderPath })).not.toThrow();
});
});
});
4 changes: 2 additions & 2 deletions packages/@o3r/core/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('new otter application', () => {
test('should build empty app', () => {

const projectName = '--project-name=test-app';
packageManagerExec(`ng add --skip-confirmation @o3r/core@${o3rVersion} --preset=all ${projectName}`, execAppOptions);
packageManagerExec(`ng add --skip-confirmation @o3r/core@${o3rVersion} --preset=all ${projectName}`, { ...execAppOptions, cwd: appFolderPath });
expect(() => packageManagerInstall(execAppOptions)).not.toThrow();

packageManagerExec(
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('new otter application', () => {
execAppOptions
);

expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();
expect(() => packageManagerRun('build', { ...execAppOptions, cwd: appFolderPath })).not.toThrow();

// should pass the e2e tests
packageManagerExec(`ng g @o3r/testing:playwright-scenario --name=test-scenario ${projectName}`, execAppOptions);
Expand Down
7 changes: 3 additions & 4 deletions packages/@o3r/test-helpers/src/prepare-test-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { minVersion } from 'semver';
import { createTestEnvironmentAngular } from './test-environments/create-test-environment-angular';
import { createTestEnvironmentAngularWithO3rCore } from './test-environments/create-test-environment-angular-with-o3r-core';
import { createTestEnvironmentBlank } from './test-environments/create-test-environment-blank';
import {createWithLock, packageManagerInstall, setPackagerManagerConfig} from './utilities';
import {createWithLock, isYarn1, packageManagerInstall, setPackagerManagerConfig, YARN_1_LATEST_VERSION} from './utilities';

/**
* 'blank' only create yarn/npm config
Expand All @@ -19,8 +19,7 @@ export type PrepareTestEnvType = 'blank' | 'angular' | 'angular-with-o3r-core' |

/**
* 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<string, string> } =
Expand All @@ -44,7 +43,7 @@ export async function prepareTestEnv(folderName: string, type: PrepareTestEnvTyp

const o3rCorePackageJson: PackageJson & { generatorDependencies?: Record<string, string> } =
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 angularVersion = minVersion(o3rCorePackageJson.devDependencies?.['@angular-devkit/schematics'] || 'latest')?.version;
const materialVersion = minVersion(o3rCorePackageJson.generatorDependencies?.['@angular/material'] || angularVersion || 'latest')?.version;
const generateMonorepo = type === 'angular-monorepo' || type === 'angular-monorepo-with-o3r-core';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ExecSyncOptions } from 'node:child_process';
import { execSync, ExecSyncOptions } from 'node:child_process';
import { cpSync, existsSync } from 'node:fs';
import path from 'node:path';
import { createWithLock, isYarn1, packageManagerAdd, packageManagerExec, packageManagerInstall } from '../utilities';
import { createTestEnvironmentAngular, CreateTestEnvironmentAngularOptions } from './create-test-environment-angular';
import { createWithLock, packageManagerAdd, packageManagerExec, packageManagerInstall } from '../utilities';

export interface CreateTestEnvironmentAngularWithO3rCoreOptions extends CreateTestEnvironmentAngularOptions {
/**
Expand Down Expand Up @@ -80,6 +80,10 @@ export async function createTestEnvironmentAngularWithO3rCore(inputOptions: Part
}
const o3rVersion = '999.0.0';
if (options.generateMonorepo) {
if (isYarn1()) {
// eslint-disable-next-line no-useless-escape
execSync('[ -f ./.yarnrc ] && grep -q "^\s*--add.ignore-workspace-root-check true\s*$" ./.yarnrc || echo "--add.ignore-workspace-root-check true" >> ./.yarnrc', execAppOptions);
}
packageManagerExec(`ng add --skip-confirmation @o3r/core@${o3rVersion}`, execAppOptions);
// FIXME: workaround for yarn pnp (same issue with node_modules but the runner won't complain if package is present in root instead of project)
packageManagerAdd(`@o3r/core@${o3rVersion}`, {...execAppOptions, cwd: path.join(appFolderPath, 'projects', 'test-app')});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createWithLock,
CreateWithLockOptions,
getPackageManager,
isYarn1,
packageManagerAdd,
PackageManagerConfig,
packageManagerExec,
Expand Down Expand Up @@ -149,7 +150,7 @@ export async function createTestEnvironmentAngular(inputOptions: Partial<CreateT
// TODO remove this if we manage to make 'workspace <> ng add' work with private registry
cpSync(path.join(appFolderPath, '.npmrc'), path.join(appFolderPath, 'projects', 'test-app', '.npmrc'));

if (getPackageManager() === 'yarn' && options.yarnVersion && Number.parseInt(options.yarnVersion.split('.')[0], 10) < 4) {
if (getPackageManager() === 'yarn' && options.yarnVersion && !isYarn1() && Number.parseInt(options.yarnVersion.split('.')[0], 10) < 4) {
execFileSync('yarn', ['plugin', 'import', 'workspace-tools'], {...execAppOptions, shell: process.platform === 'win32'});
}
}
Expand Down
9 changes: 9 additions & 0 deletions packages/@o3r/test-helpers/src/utilities/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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`
Expand Down

0 comments on commit 48b6dff

Please sign in to comment.