-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { | ||
getDefaultExecSyncOptions, | ||
getPackageManager, | ||
getYarnVersionFromRoot, | ||
isYarn1Enforced, | ||
packageManagerCreate, | ||
packageManagerExec, | ||
packageManagerInstall, | ||
|
@@ -25,8 +25,9 @@ describe('Create new sdk command', () => { | |
setupLocalRegistry(); | ||
beforeEach(async () => { | ||
const isYarnTest = packageManager.startsWith('yarn'); | ||
const yarnVersion = isYarnTest ? getYarnVersionFromRoot(process.cwd()) || 'latest' : undefined; | ||
sdkFolderPath = (await prepareTestEnv(projectName, {type: 'blank', yarnVersion })).workspacePath; | ||
const testEnv = await prepareTestEnv(projectName, { type: 'blank' }); | ||
sdkFolderPath = testEnv.workspacePath; | ||
const yarnVersion = testEnv.packageManagerConfig.yarnVersion; | ||
sdkPackagePath = path.join(sdkFolderPath, sdkPackageName.replace(/^@/, '')); | ||
execAppOptions.cwd = sdkFolderPath; | ||
|
||
|
@@ -35,9 +36,10 @@ 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 = isYarn1Enforced() ? '.yarnrc' : '.yarnrc.yml'; | ||
cpSync(path.join(sdkFolderPath, yarnConfigFile), path.join(sdkPackagePath, yarnConfigFile)); | ||
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 | ||
|
@@ -55,39 +57,41 @@ 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, !isYarn1Enforced() ? 'npm' : undefined) | ||
).not.toThrow(); | ||
Check failure on line 61 in packages/@ama-sdk/create/src/index.it.spec.ts GitHub Actions / it-tests / it-tests (ubuntu-latest, yarn1, o3r-project-with-app)Create new sdk command › should generate a full SDK when the specification is provided
|
||
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow(); | ||
expect(() => packageManagerRun({ script: 'build' }, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow(); | ||
}); | ||
|
||
test('should generate an empty SDK ready to be used', () => { | ||
expect(() => packageManagerCreate({script: '@ama-sdk', args: ['typescript', sdkPackageName]}, execAppOptions)).not.toThrow(); | ||
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow(); | ||
expect(() => packageManagerCreate({ | ||
script: '@ama-sdk', | ||
args: ['typescript', sdkPackageName] }, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined)).not.toThrow(); | ||
Check failure on line 68 in packages/@ama-sdk/create/src/index.it.spec.ts GitHub Actions / it-tests / it-tests (ubuntu-latest, yarn, o3r-project-with-app)Create new sdk command › should generate an empty SDK ready to be used
Check failure on line 68 in packages/@ama-sdk/create/src/index.it.spec.ts GitHub Actions / it-tests / it-tests (ubuntu-latest, yarn1, o3r-project-with-app)Create new sdk command › should generate an empty SDK ready to be used
Check failure on line 68 in packages/@ama-sdk/create/src/index.it.spec.ts GitHub Actions / it-tests / it-tests (windows-latest, yarn, o3r-project-with-app)Create new sdk command › should generate an empty SDK ready to be used
|
||
expect(() => packageManagerRun({ script: 'build' }, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow(); | ||
expect(() => | ||
packageManagerExec({ | ||
script: 'schematics', | ||
args: ['@ama-sdk/schematics:typescript-core', '--spec-path', path.join(path.relative(sdkPackagePath, sdkFolderPath), 'swagger-spec.yml')] | ||
}, { ...execAppOptions, cwd: sdkPackagePath }) | ||
).not.toThrow(); | ||
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow(); | ||
expect(() => packageManagerRun({script: 'doc:generate'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow(); | ||
expect(() => packageManagerRun({ script: 'build' }, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow(); | ||
expect(() => packageManagerRun({ script: 'doc:generate' }, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow(); | ||
}); | ||
|
||
test('should fail when there is an error', () => { | ||
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, !isYarn1Enforced() ? 'npm' : undefined) | ||
).toThrow(); | ||
}); | ||
|
||
test('should use pinned versions when --exact-o3r-version is used', () => { | ||
expect(() => | ||
packageManagerCreate({ | ||
script: `@ama-sdk@${o3rVersion}`, | ||
script: `@ama-sdk`, | ||
args: ['typescript', sdkPackageName, '--exact-o3r-version', '--package-manager', packageManager, '--spec-path', path.join(sdkFolderPath, 'swagger-spec.yml')] | ||
}, execAppOptions) | ||
}, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined) | ||
).not.toThrow(); | ||
Check failure on line 95 in packages/@ama-sdk/create/src/index.it.spec.ts GitHub Actions / it-tests / it-tests (ubuntu-latest, yarn1, o3r-project-with-app)Create new sdk command › should use pinned versions when --exact-o3r-version is used
|
||
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow(); | ||
const packageJson = JSON.parse(fs.readFileSync(path.join(sdkPackagePath, 'package.json'), 'utf-8')); | ||
|