Skip to content

Commit

Permalink
test: use timestamp in the version used for verdaccio
Browse files Browse the repository at this point in the history
  • Loading branch information
fpaul-1A committed Apr 25, 2024
1 parent fba02d2 commit d6f9ed0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 35 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/it-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ jobs:
!.cache/test-app/cache/@ama-terasu*
!.cache/test-app/cache/@o3r*
key: ${{ runner.os }}-test-app-${{ matrix.packageManager }}-${{ env.currentMonth }}
- name: Make sure that internal packages are not cached for whatever reason - yarn
run: npx --yes rimraf -g ".cache/test-app/cache/@{o3r,ama-sdk,ama-terasu}-*"
- name: Make sure that internal packages are not cached for whatever reason - npm
run: |
npm cache --cache=.cache/test-app/npm-cache ls | grep 127.0.0.1:4873 | xargs -d'\n' -r -n 1 npm cache --cache=.cache/test-app/npm-cache clean || true
npx --yes -p replace-in-files-cli replace-in-files --regex=".*127.0.0.1:4873.*" --replacement="" ".cache/test-app/npm-cache/_cacache/index-v5/**/*"
shell: bash
- uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
name: Download verdaccio storage prepared in the previous job
with:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"verdaccio:start-persistent": "docker run -d -it --rm --name verdaccio -p 4873:4873 -v \"$(yarn get:current-dir)/.verdaccio/conf\":/verdaccio/conf -v \"$(yarn get:current-dir)/.verdaccio/storage\":/verdaccio/storage:z verdaccio/verdaccio",
"verdaccio:clean": "rimraf -g \".verdaccio/storage/@{o3r,ama-sdk,ama-terasu}\"",
"verdaccio:login": "yarn cpy --cwd=./.verdaccio/conf .npmrc . --rename=.npmrc-logged && npx --yes npm-cli-login -u verdaccio -p verdaccio -e [email protected] -r http://127.0.0.1:4873 --config-path \".verdaccio/conf/.npmrc-logged\"",
"verdaccio:publish": "yarn verdaccio:clean && yarn set:version 999.0.0 --include \"!**/!(dist)/package.json\" --include !package.json && yarn verdaccio:login && yarn run publish --userconfig \".verdaccio/conf/.npmrc-logged\" --tag=latest --@o3r:registry=http://127.0.0.1:4873 --@ama-sdk:registry=http://127.0.0.1:4873 --@ama-terasu:registry=http://127.0.0.1:4873",
"verdaccio:publish": "yarn verdaccio:clean && yarn set:version 999.0.$(node -e 'process.stdout.write(String(Date.now()))') --include \"!**/!(dist)/package.json\" --include !package.json && yarn verdaccio:login && yarn run publish --userconfig \".verdaccio/conf/.npmrc-logged\" --tag=latest --@o3r:registry=http://127.0.0.1:4873 --@ama-sdk:registry=http://127.0.0.1:4873 --@ama-terasu:registry=http://127.0.0.1:4873",
"verdaccio:stop": "docker container stop $(docker ps -a -q --filter=\"name=verdaccio\")",
"verdaccio:all": "yarn verdaccio:stop && yarn verdaccio:start && yarn verdaccio:publish",
"watch:vscode-extension": "yarn nx run vscode-extension:compile:watch",
Expand Down
4 changes: 2 additions & 2 deletions packages/@ama-sdk/create/src/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('Create new sdk command', () => {
test('should use pinned versions when --exact-o3r-version is used', () => {
expect(() =>
packageManagerCreate({
script: `@ama-sdk@${o3rEnvironment.testEnvironment.o3rVersion}`,
script: `@ama-sdk@${o3rEnvironment.testEnvironment.o3rExactVersion}`,
args: ['typescript', sdkPackageName, '--exact-o3r-version', '--package-manager', packageManager, '--spec-path', path.join(sdkFolderPath, 'swagger-spec.yml')]
}, execAppOptions)
).not.toThrow();
Expand All @@ -125,7 +125,7 @@ describe('Create new sdk command', () => {
[
...Object.entries(packageJson.dependencies), ...Object.entries(packageJson.devDependencies), ...Object.entries(resolutions)
].filter(([dep]) => dep.startsWith('@o3r/') || dep.startsWith('@ama-sdk/')).forEach(([,version]) => {
expect(version).toBe(o3rEnvironment.testEnvironment.o3rVersion);
expect(version).toBe(o3rEnvironment.testEnvironment.o3rExactVersion);
});
});
});
6 changes: 3 additions & 3 deletions packages/@o3r/create/src/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Create new otter project command', () => {
});

test('should generate a project with an application with --exact-o3r-version', async () => {
const { workspacePath, packageManagerConfig, o3rVersion } = o3rEnvironment.testEnvironment;
const { workspacePath, packageManagerConfig, o3rExactVersion } = o3rEnvironment.testEnvironment;
const inAppPath = path.join(workspacePath, workspaceProjectName);
const execWorkspaceOptions = {...defaultExecOptions, cwd: workspacePath };
const execInAppOptions = {...defaultExecOptions, cwd: inAppPath };
Expand All @@ -57,7 +57,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@${o3rExactVersion}`, args: [workspaceProjectName, ...createOptions] }, execWorkspaceOptions, 'npm')).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 All @@ -75,7 +75,7 @@ describe('Create new otter project command', () => {
...Object.entries(rootPackageJson.dependencies), ...Object.entries(rootPackageJson.devDependencies), ...Object.entries(resolutions),
...Object.entries(appPackageJson.dependencies), ...Object.entries(appPackageJson.devDependencies)
].filter(([dep]) => dep.startsWith('@o3r/') || dep.startsWith('@ama-sdk/')).forEach(([,version]) => {
expect(version).toBe(o3rVersion);
expect(version).toBe(o3rExactVersion);
});
});
});
33 changes: 12 additions & 21 deletions packages/@o3r/test-helpers/src/prepare-test-env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync, ExecSyncOptions } from 'node:child_process';
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync } from 'node:fs';
import { execFileSync, 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';
Expand Down Expand Up @@ -46,8 +46,7 @@ export async function prepareTestEnv(folderName: string, options?: PrepareTestEn
const itTestsFolderPath = path.resolve(rootFolderPath, '..', 'it-tests');
const workspacePath = path.resolve(itTestsFolderPath, folderName);
const globalFolderPath = path.resolve(rootFolderPath, '.cache', 'test-app');
const cacheFolderPath = path.resolve(globalFolderPath, 'cache');
const o3rVersion = '999.0.0';
const o3rVersion = '~999';

JSON.parse(readFileSync(path.join(rootFolderPath, 'packages', '@o3r', 'core', 'package.json')).toString());
const yarnVersion: string = yarnVersionParam || getYarnVersionFromRoot(rootFolderPath);
Expand All @@ -58,22 +57,6 @@ export async function prepareTestEnv(folderName: string, options?: PrepareTestEn
env: {...process.env, NODE_OPTIONS: '', CI: 'true'}
};

// Remove all cache entries relative to local workspaces (@o3r, @ama-sdk, @ama-terasu)
if (!!process.env.CI && existsSync(cacheFolderPath)) {
const workspacesList = execSync('yarn workspaces:list', { stdio: 'pipe' }).toString().split(path.delimiter)
.map((workspace) => workspace.replace('packages/', '').replace(/\//, '-'))
.filter((workspace) => !!workspace);
readdirSync(cacheFolderPath).forEach((fileName) => {
if (workspacesList.some((workspace) => fileName.startsWith(workspace))) {
const cacheFile = path.join(cacheFolderPath, fileName);
// Not ideal solution but the tests are running in parallel, so we cannot always clean the cache
if (Date.now() - statSync(cacheFile).birthtime.getTime() > (60 * 60 * 1000)) {
rmSync(cacheFile);
}
}
});
}

const packageManagerConfig = {
yarnVersion,
globalFolderPath,
Expand All @@ -89,6 +72,13 @@ export async function prepareTestEnv(folderName: string, options?: PrepareTestEn
return Promise.resolve();
}, {lockFilePath: `${itTestsFolderPath}.lock`, cwd: path.join(rootFolderPath, '..'), appDirectory: 'it-tests'});
}
const o3rExactVersion = execFileSync('npm', ['info', '@o3r/create', 'version'], {
...execAppOptions,
cwd: itTestsFolderPath,
stdio: 'pipe',
encoding: 'utf8',
shell: true
}).replace(/\s/g, '');

// Remove existing app
if (existsSync(workspacePath)) {
Expand Down Expand Up @@ -158,6 +148,7 @@ export async function prepareTestEnv(folderName: string, options?: PrepareTestEn
untouchedProject,
untouchedProjectPath,
packageManagerConfig,
o3rVersion
o3rVersion,
o3rExactVersion
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface CreateTestEnvironmentOtterProjectWithAppOptions extends CreateW
logger?: Logger;
}

const o3rVersion = '999.0.0';
const o3rVersion = '~999';

/**
* Generate a base angular app with minimal necessary dependencies
Expand Down

0 comments on commit d6f9ed0

Please sign in to comment.