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 May 15, 2024
1 parent 89fcb9b commit aeb9bbe
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 51 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/it-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,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:
Expand Down Expand Up @@ -101,9 +101,19 @@ jobs:
npx --yes wait-on http://127.0.0.1:4873 -t 180000
fi
shell: bash
- name: Rename .npmrc for yarn 1
if: matrix.packageManager == 'yarn1'
id: rename-npmrc
run: mv -f .npmrc .npmrc-backup
shell: bash
- name: Test
id: it-tests
run: yarn test-int
- name: Revert .npmrc rename for yarn 1
if: matrix.packageManager == 'yarn1'
id: revert-rename-npmrc
run: mv -f .npmrc-backup .npmrc
shell: bash
- name: Zip generated app on failure
if: failure() && steps.it-tests.conclusion == 'failure'
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ coverage

# Nx
.nx/cache

# Tests
openapitools.json
35 changes: 20 additions & 15 deletions packages/@ama-sdk/create/src/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* @jest-environment @o3r/test-helpers/jest-environment
* @jest-environment-o3r-app-folder test-create-sdk
* @jest-environment-o3r-type blank
* @jest-environment-o3r-package-scope ama-sdk-create
*/
const o3rEnvironment = globalThis.o3rEnvironment;

import {
getDefaultExecSyncOptions,
getPackageManager,
getYarnVersionFromRoot,
isYarn1Enforced,
packageManagerCreate,
packageManagerExec,
packageManagerInstall,
Expand All @@ -24,11 +25,13 @@ let sdkFolderPath: string;
let sdkPackagePath: string;
const execAppOptions = getDefaultExecSyncOptions();
const packageManager = getPackageManager();
const describeSkipIfYarn1 = isYarn1Enforced() ? describe : describe.skip;

describeSkipIfYarn1('Create new sdk command', () => {

describe('Create new sdk command', () => {
beforeEach(() => {
const isYarnTest = packageManager.startsWith('yarn');
const yarnVersion = isYarnTest ? getYarnVersionFromRoot(process.cwd()) || 'latest' : undefined;
const yarnVersion = o3rEnvironment.testEnvironment.packageManagerConfig.yarnVersion;
sdkFolderPath = o3rEnvironment.testEnvironment.workspacePath;
sdkPackagePath = path.join(sdkFolderPath, sdkPackageName.replace(/^@/, ''));
execAppOptions.cwd = sdkFolderPath;
Expand All @@ -38,18 +41,16 @@ describe('Create new sdk command', () => {
packageManagerInstall(execAppOptions);

// copy yarnrc config to generated SDK
mkdirSync(sdkPackagePath, {recursive: true});
cpSync(path.join(sdkFolderPath, '.yarnrc.yml'), path.join(sdkPackagePath, '.yarnrc.yml'));
cpSync(path.join(sdkFolderPath, '.yarn'), path.join(sdkPackagePath, '.yarn'), {recursive: true});
mkdirSync(sdkPackagePath, { recursive: true });
const yarnConfigFile = '.yarnrc.yml';
cpSync(path.join(sdkFolderPath, yarnConfigFile), path.join(sdkPackagePath, yarnConfigFile));

Check failure on line 46 in packages/@ama-sdk/create/src/index.it.spec.ts

View workflow job for this annotation

GitHub Actions / IT Tests report-ubuntu-latest-yarn1

Create new sdk command ► Create new sdk command should generate a light SDK when the specification is provided ► Create new sdk command should generate a light SDK when the specification is provided

Failed test found in: @ama-sdk/create/dist-test/it-report.xml Error: Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk/.yarnrc.yml'
Raw output
Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk/.yarnrc.yml'
    at Object.lstatSync (node:fs:1634:25)
    at NodeFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61675:26)
    at makeCallSync.subPath.subPath (/home/runner/work/otter/otter/.pnp.cjs:62206:26)
    at ZipOpenFS.makeCallSync (/home/runner/work/otter/otter/.pnp.cjs:62645:14)
    at ZipOpenFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:62205:17)
    at VirtualFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at PosixFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at NodePathFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at getStatsSync (node:internal/fs/cp/cp-sync:120:19)
    at checkPathsSync (node:internal/fs/cp/cp-sync:72:33)
    at cpSyncFn (node:internal/fs/cp/cp-sync:58:42)
    at cpSync (node:fs:3047:3)
    at Object.<anonymous> (/home/runner/work/otter/otter/packages/@ama-sdk/create/src/index.it.spec.ts:46:13)
    at Promise.then.completed (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:298:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:231:10)
    at _callCircusHook (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:281:40)
    at _runTest (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:246:5)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:126:9)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:121:9)
    at run (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:71:3)
    at runAndTransformResultsToJestFormat (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    at jestAdapter (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    at runTestInternal (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/testWorker.js:106:12)

Check failure on line 46 in packages/@ama-sdk/create/src/index.it.spec.ts

View workflow job for this annotation

GitHub Actions / IT Tests report-ubuntu-latest-yarn1

Create new sdk command ► Create new sdk command should generate a full SDK when the specification is provided ► Create new sdk command should generate a full SDK when the specification is provided

Failed test found in: @ama-sdk/create/dist-test/it-report.xml Error: Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk1/.yarnrc.yml'
Raw output
Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk1/.yarnrc.yml'
    at Object.lstatSync (node:fs:1634:25)
    at NodeFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61675:26)
    at makeCallSync.subPath.subPath (/home/runner/work/otter/otter/.pnp.cjs:62206:26)
    at ZipOpenFS.makeCallSync (/home/runner/work/otter/otter/.pnp.cjs:62645:14)
    at ZipOpenFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:62205:17)
    at VirtualFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at PosixFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at NodePathFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at getStatsSync (node:internal/fs/cp/cp-sync:120:19)
    at checkPathsSync (node:internal/fs/cp/cp-sync:72:33)
    at cpSyncFn (node:internal/fs/cp/cp-sync:58:42)
    at cpSync (node:fs:3047:3)
    at Object.<anonymous> (/home/runner/work/otter/otter/packages/@ama-sdk/create/src/index.it.spec.ts:46:13)
    at Promise.then.completed (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:298:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:231:10)
    at _callCircusHook (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:281:40)
    at _runTest (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:246:5)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:126:9)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:121:9)
    at run (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:71:3)
    at runAndTransformResultsToJestFormat (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    at jestAdapter (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    at runTestInternal (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/testWorker.js:106:12)

Check failure on line 46 in packages/@ama-sdk/create/src/index.it.spec.ts

View workflow job for this annotation

GitHub Actions / IT Tests report-ubuntu-latest-yarn1

Create new sdk command ► Create new sdk command should generate a full SDK when the specification is provided as npm dependency ► Create new sdk command should generate a full SDK when the specification is provided as npm dependency

Failed test found in: @ama-sdk/create/dist-test/it-report.xml Error: Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk2/.yarnrc.yml'
Raw output
Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk2/.yarnrc.yml'
    at Object.lstatSync (node:fs:1634:25)
    at NodeFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61675:26)
    at makeCallSync.subPath.subPath (/home/runner/work/otter/otter/.pnp.cjs:62206:26)
    at ZipOpenFS.makeCallSync (/home/runner/work/otter/otter/.pnp.cjs:62645:14)
    at ZipOpenFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:62205:17)
    at VirtualFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at PosixFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at NodePathFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at getStatsSync (node:internal/fs/cp/cp-sync:120:19)
    at checkPathsSync (node:internal/fs/cp/cp-sync:72:33)
    at cpSyncFn (node:internal/fs/cp/cp-sync:58:42)
    at cpSync (node:fs:3047:3)
    at Object.<anonymous> (/home/runner/work/otter/otter/packages/@ama-sdk/create/src/index.it.spec.ts:46:13)
    at Promise.then.completed (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:298:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:231:10)
    at _callCircusHook (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:281:40)
    at _runTest (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:246:5)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:126:9)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:121:9)
    at run (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:71:3)
    at runAndTransformResultsToJestFormat (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    at jestAdapter (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    at runTestInternal (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/testWorker.js:106:12)

Check failure on line 46 in packages/@ama-sdk/create/src/index.it.spec.ts

View workflow job for this annotation

GitHub Actions / IT Tests report-ubuntu-latest-yarn1

Create new sdk command ► Create new sdk command should generate an SDK with no package scope ► Create new sdk command should generate an SDK with no package scope

Failed test found in: @ama-sdk/create/dist-test/it-report.xml Error: Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk3/.yarnrc.yml'
Raw output
Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk3/.yarnrc.yml'
    at Object.lstatSync (node:fs:1634:25)
    at NodeFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61675:26)
    at makeCallSync.subPath.subPath (/home/runner/work/otter/otter/.pnp.cjs:62206:26)
    at ZipOpenFS.makeCallSync (/home/runner/work/otter/otter/.pnp.cjs:62645:14)
    at ZipOpenFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:62205:17)
    at VirtualFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at PosixFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at NodePathFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at getStatsSync (node:internal/fs/cp/cp-sync:120:19)
    at checkPathsSync (node:internal/fs/cp/cp-sync:72:33)
    at cpSyncFn (node:internal/fs/cp/cp-sync:58:42)
    at cpSync (node:fs:3047:3)
    at Object.<anonymous> (/home/runner/work/otter/otter/packages/@ama-sdk/create/src/index.it.spec.ts:46:13)
    at Promise.then.completed (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:298:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:231:10)
    at _callCircusHook (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:281:40)
    at _runTest (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:246:5)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:126:9)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:121:9)
    at run (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:71:3)
    at runAndTransformResultsToJestFormat (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    at jestAdapter (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    at runTestInternal (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/testWorker.js:106:12)

Check failure on line 46 in packages/@ama-sdk/create/src/index.it.spec.ts

View workflow job for this annotation

GitHub Actions / IT Tests report-ubuntu-latest-yarn1

Create new sdk command ► Create new sdk command should generate an empty SDK ready to be used ► Create new sdk command should generate an empty SDK ready to be used

Failed test found in: @ama-sdk/create/dist-test/it-report.xml Error: Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk4/.yarnrc.yml'
Raw output
Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk4/.yarnrc.yml'
    at Object.lstatSync (node:fs:1634:25)
    at NodeFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61675:26)
    at makeCallSync.subPath.subPath (/home/runner/work/otter/otter/.pnp.cjs:62206:26)
    at ZipOpenFS.makeCallSync (/home/runner/work/otter/otter/.pnp.cjs:62645:14)
    at ZipOpenFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:62205:17)
    at VirtualFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at PosixFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at NodePathFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at getStatsSync (node:internal/fs/cp/cp-sync:120:19)
    at checkPathsSync (node:internal/fs/cp/cp-sync:72:33)
    at cpSyncFn (node:internal/fs/cp/cp-sync:58:42)
    at cpSync (node:fs:3047:3)
    at Object.<anonymous> (/home/runner/work/otter/otter/packages/@ama-sdk/create/src/index.it.spec.ts:46:13)
    at Promise.then.completed (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:298:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:231:10)
    at _callCircusHook (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:281:40)
    at _runTest (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:246:5)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:126:9)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:121:9)
    at run (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:71:3)
    at runAndTransformResultsToJestFormat (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    at jestAdapter (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    at runTestInternal (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/testWorker.js:106:12)

Check failure on line 46 in packages/@ama-sdk/create/src/index.it.spec.ts

View workflow job for this annotation

GitHub Actions / IT Tests report-ubuntu-latest-yarn1

Create new sdk command ► Create new sdk command should fail when there is an error ► Create new sdk command should fail when there is an error

Failed test found in: @ama-sdk/create/dist-test/it-report.xml Error: Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk5/.yarnrc.yml'
Raw output
Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk5/.yarnrc.yml'
    at Object.lstatSync (node:fs:1634:25)
    at NodeFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61675:26)
    at makeCallSync.subPath.subPath (/home/runner/work/otter/otter/.pnp.cjs:62206:26)
    at ZipOpenFS.makeCallSync (/home/runner/work/otter/otter/.pnp.cjs:62645:14)
    at ZipOpenFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:62205:17)
    at VirtualFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at PosixFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at NodePathFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at getStatsSync (node:internal/fs/cp/cp-sync:120:19)
    at checkPathsSync (node:internal/fs/cp/cp-sync:72:33)
    at cpSyncFn (node:internal/fs/cp/cp-sync:58:42)
    at cpSync (node:fs:3047:3)
    at Object.<anonymous> (/home/runner/work/otter/otter/packages/@ama-sdk/create/src/index.it.spec.ts:46:13)
    at Promise.then.completed (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:298:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:231:10)
    at _callCircusHook (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:281:40)
    at _runTest (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:246:5)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:126:9)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:121:9)
    at run (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:71:3)
    at runAndTransformResultsToJestFormat (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    at jestAdapter (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    at runTestInternal (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/testWorker.js:106:12)

Check failure on line 46 in packages/@ama-sdk/create/src/index.it.spec.ts

View workflow job for this annotation

GitHub Actions / IT Tests report-ubuntu-latest-yarn1

Create new sdk command ► Create new sdk command should use pinned versions when --exact-o3r-version is used ► Create new sdk command should use pinned versions when --exact-o3r-version is used

Failed test found in: @ama-sdk/create/dist-test/it-report.xml Error: Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk6/.yarnrc.yml'
Raw output
Error: ENOENT: no such file or directory, lstat '/home/runner/work/otter/it-tests/ama-sdk-create/test-create-sdk6/.yarnrc.yml'
    at Object.lstatSync (node:fs:1634:25)
    at NodeFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61675:26)
    at makeCallSync.subPath.subPath (/home/runner/work/otter/otter/.pnp.cjs:62206:26)
    at ZipOpenFS.makeCallSync (/home/runner/work/otter/otter/.pnp.cjs:62645:14)
    at ZipOpenFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:62205:17)
    at VirtualFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at PosixFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at NodePathFS.lstatSync (/home/runner/work/otter/otter/.pnp.cjs:61341:24)
    at getStatsSync (node:internal/fs/cp/cp-sync:120:19)
    at checkPathsSync (node:internal/fs/cp/cp-sync:72:33)
    at cpSyncFn (node:internal/fs/cp/cp-sync:58:42)
    at cpSync (node:fs:3047:3)
    at Object.<anonymous> (/home/runner/work/otter/otter/packages/@ama-sdk/create/src/index.it.spec.ts:46:13)
    at Promise.then.completed (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:298:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/utils.js:231:10)
    at _callCircusHook (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:281:40)
    at _runTest (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:246:5)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:126:9)
    at _runTestsForDescribeBlock (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:121:9)
    at run (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/run.js:71:3)
    at runAndTransformResultsToJestFormat (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    at jestAdapter (/home/runner/work/otter/otter/.yarn/cache/jest-circus-npm-29.7.0-f7679858c6-716a8e3f40.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    at runTestInternal (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/otter/otter/.yarn/cache/jest-runner-npm-29.7.0-3bc9f82b58-9d8748a494.zip/node_modules/jest-runner/build/testWorker.js:106:12)
cpSync(path.join(sdkFolderPath, '.yarn'), path.join(sdkPackagePath, '.yarn'), { recursive: true });
fs.writeFileSync(path.join(sdkPackagePath, 'yarn.lock'), '');
} else {
// copy npmrc config to generated SDK
mkdirSync(sdkPackagePath, { recursive: true });
cpSync(path.join(sdkFolderPath, '.npmrc'), path.join(sdkPackagePath, '.npmrc'));
}
});

beforeEach(() => {
cpSync(path.join(__dirname, '..', 'testing', 'mocks', 'MOCK_swagger_updated.yaml'), path.join(sdkFolderPath, 'swagger-spec.yml'));
cpSync(path.join(__dirname, '..', 'testing', 'mocks', 'MOCK_DATE_UTILS_swagger.yaml'), path.join(sdkFolderPath, 'swagger-spec-with-date.yml'));
});
Expand All @@ -59,7 +60,7 @@ describe('Create new sdk command', () => {
packageManagerCreate({
script: '@ama-sdk',
args: ['typescript', sdkPackageName, '--package-manager', packageManager, '--spec-path', path.join(sdkFolderPath, 'swagger-spec.yml')]
}, execAppOptions)
}, execAppOptions, 'npm')
).not.toThrow();
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
expect(existsSync(path.join(sdkPackagePath, 'src', 'models', 'base', 'pet', 'pet.reviver.ts'))).toBeFalsy();
Expand Down Expand Up @@ -111,7 +112,10 @@ describe('Create new sdk command', () => {
});

test('should generate an empty SDK ready to be used', () => {
expect(() => packageManagerCreate({script: '@ama-sdk', args: ['typescript', sdkPackageName]}, execAppOptions)).not.toThrow();
expect(() => packageManagerCreate({
script: '@ama-sdk',
args: ['typescript', sdkPackageName, '--package-manager', packageManager]
}, execAppOptions, 'npm')).not.toThrow();
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
expect(() =>
packageManagerExec({
Expand All @@ -127,17 +131,18 @@ describe('Create new sdk command', () => {
expect(() =>
packageManagerCreate({
script: '@ama-sdk',
args: ['typescript', sdkPackageName, '--package-manager', packageManager, '--spec-path','./missing-file.yml']
}, execAppOptions)
args: ['typescript', sdkPackageName, '--package-manager', packageManager, '--spec-path', './missing-file.yml']
}, execAppOptions, 'npm')
).toThrow();
});

test('should use pinned versions when --exact-o3r-version is used', () => {
const versionToInstall = isYarn1Enforced() ? '' : `@${o3rEnvironment.testEnvironment.o3rVersion}`;
expect(() =>
packageManagerCreate({
script: `@ama-sdk@${o3rEnvironment.testEnvironment.o3rExactVersion}`,
script: `@ama-sdk@${versionToInstall}`,
args: ['typescript', sdkPackageName, '--exact-o3r-version', '--package-manager', packageManager, '--spec-path', path.join(sdkFolderPath, 'swagger-spec.yml')]
}, execAppOptions)
}, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined)
).not.toThrow();
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
const packageJson = JSON.parse(fs.readFileSync(path.join(sdkPackagePath, 'package.json'), 'utf-8'));
Expand Down
9 changes: 6 additions & 3 deletions packages/@o3r/create/src/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
* @jest-environment @o3r/test-helpers/jest-environment
* @jest-environment-o3r-app-folder test-create-app
* @jest-environment-o3r-type blank
* @jest-environment-o3r-package-scope o3r-create
*/
const o3rEnvironment = globalThis.o3rEnvironment;

import {
getDefaultExecSyncOptions,
getPackageManager,
isYarn1Enforced,
packageManagerCreate,
packageManagerExec,
packageManagerInstall,
Expand All @@ -20,10 +22,11 @@ import * as path from 'node:path';

const defaultExecOptions = getDefaultExecSyncOptions();
const workspaceProjectName = 'my-project';
const describeSkipIfYarn1 = isYarn1Enforced() ? describe : describe.skip;

describe('Create new otter project command', () => {
describeSkipIfYarn1('Create new otter project command', () => {
test('should generate a project with an application', async () => {
const { workspacePath, packageManagerConfig, o3rVersion } = o3rEnvironment.testEnvironment;
const { workspacePath, packageManagerConfig } = o3rEnvironment.testEnvironment;
const inAppPath = path.join(workspacePath, workspaceProjectName);
const execWorkspaceOptions = {...defaultExecOptions, cwd: workspacePath };
const execInAppOptions = {...defaultExecOptions, cwd: inAppPath };
Expand All @@ -33,7 +36,7 @@ describe('Create new otter project command', () => {
await fs.mkdir(inAppPath, { recursive: true });
setPackagerManagerConfig(packageManagerConfig, execInAppOptions);

expect(() => packageManagerCreate({ script: `@o3r@${o3rVersion}`, args: [workspaceProjectName, ...createOptions] }, execWorkspaceOptions, 'npm')).not.toThrow();
expect(() => packageManagerCreate({ script: `@o3r`, args: [workspaceProjectName, ...createOptions] }, execWorkspaceOptions, !isYarn1Enforced() ? 'npm' : undefined)).not.toThrow();
expect(existsSync(path.join(inAppPath, 'angular.json'))).toBe(true);
expect(existsSync(path.join(inAppPath, 'package.json'))).toBe(true);
expect(() => packageManagerInstall(execInAppOptions)).not.toThrow();
Expand Down
6 changes: 3 additions & 3 deletions packages/@o3r/create/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ const prepareWorkspace = (relativeDirectory = '.', projectPackageManager = 'npm'
cwd
}));
};

const isYarn1 = packageManager === 'yarn' && argv['yarn-version']?.split('.')[0] === '1';
const addOtterFramework = (relativeDirectory = '.', projectPackageManager = 'npm') => {
const cwd = resolve(process.cwd(), relativeDirectory);
const runner = process.platform === 'win32' ? `${projectPackageManager}.cmd` : projectPackageManager;
const options = schematicsCliOptions
.flat();

exitProcessIfErrorInSpawnSync(3, spawnSync(runner, ['exec', 'ng', 'add', `@o3r/core@${exactO3rVersion ? '' : '~'}${version}`, ...(projectPackageManager === 'npm' ? ['--'] : []), ...options], {
exitProcessIfErrorInSpawnSync(3, spawnSync(runner, [isYarn1 ? 'run' : 'exec', 'ng', 'add', `@o3r/core@${exactO3rVersion ? '' : '~'}${version}`,
...((projectPackageManager === 'npm' || isYarn1) ? ['--'] : []), ...options], {
stdio: 'inherit',
cwd,
shell: true,
Expand Down
6 changes: 3 additions & 3 deletions packages/@o3r/telemetry/src/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import { execSync } from 'node:child_process';
import * as path from 'node:path';

/** Support NPM package managers */
type SupportedPackageManagers = 'npm' | 'yarn';
type SupportedPackageManagers = 'npm' | 'yarn' | 'yarn1';

/**
* Determine if the given packager manager is supported
* @param name Name of the package manager
*/
function isSupportedPackageManager(name?: any): name is SupportedPackageManagers {
return name === 'yarn' || name === 'npm';
return ['yarn', 'yarn1', 'npm'].includes(name);
}

/**
* Get package manager used
*/
function getPackageManager() {
if (isSupportedPackageManager(process.env?.ENFORCED_PACKAGE_MANAGER)) {
return process.env.ENFORCED_PACKAGE_MANAGER;
return (process.env.ENFORCED_PACKAGE_MANAGE === 'npm') ? 'npm' : 'yarn';
}
return (process.env?.npm_execpath?.includes('yarn') && 'yarn') || 'npm';
}
Expand Down
6 changes: 5 additions & 1 deletion packages/@o3r/test-helpers/src/jest-environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ export class JestEnvironmentO3r extends NodeTestEnvironment {
*/
private readonly testEnvironments: Record<string, TestEnvironment> = {};

/** identifier of the package on which the tests are run */
private readonly packageScope: string | undefined;

constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {
super(config, context);
// testEnvironment is undefined now but will be defined when test runs
this.global.o3rEnvironment = {} as typeof this.global.o3rEnvironment;
this.appFolder = context.docblockPragmas['jest-environment-o3r-app-folder'] as string;
this.prepareTestEnvType = context.docblockPragmas['jest-environment-o3r-type'] as PrepareTestEnvType | undefined;
this.packageScope = context.docblockPragmas['jest-environment-o3r-package-scope'] as string | undefined;
}

/**
Expand Down Expand Up @@ -87,7 +91,7 @@ export class JestEnvironmentO3r extends NodeTestEnvironment {
// Create test environment before test starts
if (event.name === 'test_start') {
const appFolder = `${this.appFolder}${this.appIndex++ || ''}`;
this.testEnvironments[event.test.name] = await prepareTestEnv(appFolder, {type: this.prepareTestEnvType});
this.testEnvironments[event.test.name] = await prepareTestEnv(appFolder, {type: this.prepareTestEnvType, packageScope: this.packageScope});
this.global.o3rEnvironment.testEnvironment = this.testEnvironments[event.test.name];
}
// Cleanup test environment after test succeeds
Expand Down
26 changes: 16 additions & 10 deletions packages/@o3r/test-helpers/src/prepare-test-env.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { execFileSync, ExecSyncOptions } from 'node:child_process';
import { execFileSync, execSync, ExecSyncOptions } from 'node:child_process';
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
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, getVersionedPackageManager, isYarn1Enforced, type Logger, packageManagerInstall, setPackagerManagerConfig, setupGit } from './utilities/index';
import { createTestEnvironmentOtterProjectWithApp } from './test-environments/create-test-environment-otter-project';
import { O3rCliError } from '@o3r/schematics';

Expand All @@ -15,8 +15,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<string, string> } =
Expand All @@ -31,6 +30,11 @@ export interface PrepareTestEnvOptions {
yarnVersion?: string;
/** Logger to use for logging */
logger?: Logger;
/**
* Scope of package used to run the create command
* Used on yarn1 tests, because it is not able to differetiate from which package scope to run the create
*/
packageScope?: string;
}

/**
Expand All @@ -43,14 +47,15 @@ export async function prepareTestEnv(folderName: string, options?: PrepareTestEn
const logger = options?.logger || console;
const yarnVersionParam = options?.yarnVersion;
const rootFolderPath = process.cwd();
const itTestsFolderPath = path.resolve(rootFolderPath, '..', 'it-tests');
const itTestsFolderPath = path.resolve(rootFolderPath, '..', 'it-tests', options?.packageScope || '');
const workspacePath = path.resolve(itTestsFolderPath, folderName);
const globalFolderPath = path.resolve(rootFolderPath, '.cache', 'test-app');
const o3rVersion = '~999';
const registry = 'http://127.0.0.1:4873';

JSON.parse(readFileSync(path.join(rootFolderPath, 'packages', '@o3r', 'core', 'package.json')).toString());
const yarnVersion: string = yarnVersionParam || getYarnVersionFromRoot(rootFolderPath);
const yarn1Version = execSync('npm view yarn version', { encoding: 'utf8' }).trim();
const yarnVersion: string = yarnVersionParam || (isYarn1Enforced() && yarn1Version) || getYarnVersionFromRoot(rootFolderPath);
const execAppOptions: ExecSyncOptions = {
cwd: workspacePath,
stdio: 'inherit',
Expand All @@ -61,17 +66,18 @@ export async function prepareTestEnv(folderName: string, options?: PrepareTestEn
const packageManagerConfig = {
yarnVersion,
globalFolderPath,
registry
registry,
...(isYarn1Enforced() ? {packageScope: options?.packageScope} : {})
};

// Create it-tests folder
if (!existsSync(itTestsFolderPath)) {
logger.debug?.(`Creating it-tests folder`);
await createWithLock(() => {
mkdirSync(itTestsFolderPath);
mkdirSync(itTestsFolderPath, { recursive: true });
setPackagerManagerConfig(packageManagerConfig, {...execAppOptions, cwd: itTestsFolderPath});
return Promise.resolve();
}, {lockFilePath: `${itTestsFolderPath}.lock`, cwd: path.join(rootFolderPath, '..'), appDirectory: 'it-tests'});
}, {lockFilePath: `${itTestsFolderPath}.lock`, cwd: path.join(rootFolderPath, '..'), appDirectory: path.join('it-tests', options?.packageScope || '')});
}
const o3rExactVersion = execFileSync('npm', ['info', '@o3r/create', 'version'], {
...execAppOptions,
Expand Down Expand Up @@ -100,7 +106,7 @@ export async function prepareTestEnv(folderName: string, options?: PrepareTestEn
let isInWorkspace = false;
let untouchedProject: undefined | string;
let untouchedProjectPath: undefined | string;
const appDirectory = `${type}-${getPackageManager()}`;
const appDirectory = `${type}-${getVersionedPackageManager()}`;
switch (type) {
case 'blank': {
await createTestEnvironmentBlank({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createWithLock,
CreateWithLockOptions,
getPackageManager,
isYarn1Enforced,
type Logger,
PackageManagerConfig,
packageManagerCreate,
Expand Down Expand Up @@ -74,9 +75,10 @@ export async function createTestEnvironmentOtterProjectWithApp(inputOptions: Par
try { mkdirSync(appFolderPath, { recursive: true }); } catch { }
setPackagerManagerConfig(options, execAppOptions);

const versionToInstall = isYarn1Enforced() ? '' : `@${o3rVersion}`;
// Create Project
const createOptions = ['--package-manager', getPackageManager(), '--skip-confirmation', ...(options.yarnVersion ? ['--yarn-version', options.yarnVersion] : [])];
packageManagerCreate({ script: `@o3r@${o3rVersion}`, args: [options.appDirectory, ...createOptions] }, { ...execAppOptions, cwd: options.cwd}, 'npm');
packageManagerCreate({ script: `@o3r${versionToInstall}`, args: [options.appDirectory, ...createOptions] }, { ...execAppOptions, cwd: options.cwd}, !isYarn1Enforced() ? 'npm' : undefined);
const gitIgnorePath = path.join(appFolderPath, '.gitignore');
if (existsSync(gitIgnorePath)) {
const gitIgnore = readFileSync(gitIgnorePath, { encoding: 'utf8' });
Expand Down
6 changes: 5 additions & 1 deletion packages/@o3r/test-helpers/src/utilities/locker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, readFileSync, rmSync, statSync, watch, writeFileSync } from 'node:fs';
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, watch, writeFileSync } from 'node:fs';
import * as path from 'node:path';

export interface LockerOptions {
Expand Down Expand Up @@ -39,6 +39,10 @@ export class Locker {
public lock(): boolean {
const pid = String(process.pid);
try {
const locDirPath = path.dirname(this.options.lockFilePath);
if (!existsSync(locDirPath)) {
mkdirSync(locDirPath, {recursive: true});
}
writeFileSync(this.options.lockFilePath, pid, {flag: this.isLockExpired() ? 'w' : 'wx'});
// Need to check if the file was created by this process
return readFileSync(this.options.lockFilePath, {encoding: 'utf8'}) === pid;
Expand Down
Loading

0 comments on commit aeb9bbe

Please sign in to comment.