|
| 1 | +import path from 'path'; |
| 2 | +import { expect } from 'chai'; |
| 3 | +import fs from 'fs-extra'; |
| 4 | +import { Helper } from '@teambit/legacy.e2e-helper'; |
| 5 | +import { resolveFrom } from '@teambit/toolbox.modules.module-resolver'; |
| 6 | + |
| 7 | +describe.only('hidden peer dependency via env.jsonc', function () { |
| 8 | + this.timeout(0); |
| 9 | + let helper: Helper; |
| 10 | + let workspaceCapsulesRootDir: string; |
| 11 | + const peerPkgName = 'is-odd'; |
| 12 | + |
| 13 | + before(() => { |
| 14 | + helper = new Helper(); |
| 15 | + helper.scopeHelper.reInitWorkspace(); |
| 16 | + // create a single component comp1 |
| 17 | + helper.fixtures.populateComponents(1); |
| 18 | + // ensure comp1 actually requires is-odd so it's considered a used peer |
| 19 | + helper.fs.appendFile('comp1/index.js', 'const isOdd = require("is-odd");'); |
| 20 | + // create env with hidden is-odd peer |
| 21 | + helper.env.setCustomNewEnv( |
| 22 | + undefined, |
| 23 | + undefined, |
| 24 | + { |
| 25 | + policy: { |
| 26 | + peers: [ |
| 27 | + { |
| 28 | + name: peerPkgName, |
| 29 | + version: '1.0.0', |
| 30 | + supportedRange: '*', |
| 31 | + hidden: true, |
| 32 | + }, |
| 33 | + ], |
| 34 | + }, |
| 35 | + }, |
| 36 | + false, |
| 37 | + 'custom-env/env1', |
| 38 | + 'custom-env/env1' |
| 39 | + ); |
| 40 | + // apply env to comp1 |
| 41 | + helper.extensions.addExtensionToVariant('comp1', `${helper.scopes.remote}/custom-env/env1`, {}); |
| 42 | + helper.extensions.addExtensionToVariant('custom-env', 'teambit.envs/env', {}); |
| 43 | + helper.extensions.workspaceJsonc.addKeyValToDependencyResolver('rootComponents', true); |
| 44 | + helper.command.install('--add-missing-deps'); |
| 45 | + helper.command.build('--skip-tests'); |
| 46 | + workspaceCapsulesRootDir = helper.command.capsuleListParsed().workspaceCapsulesRootDir; |
| 47 | + }); |
| 48 | + |
| 49 | + after(() => { |
| 50 | + helper.scopeHelper.destroy(); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should have is-odd/package.json present in the workspace root node_modules', () => { |
| 54 | + const isOddPkgJsonPath = resolveFrom(helper.fixtures.scopes.localPath, ['is-odd/package.json']); |
| 55 | + expect(fs.existsSync(isOddPkgJsonPath)).to.be.true; |
| 56 | + }); |
| 57 | + |
| 58 | + it('should exclude is-odd from capsule package.json peerDependencies', () => { |
| 59 | + const pkgJsonPath = path.join(workspaceCapsulesRootDir, `${helper.scopes.remote}_comp1/package.json`); |
| 60 | + const pkgJson = fs.readJsonSync(pkgJsonPath); |
| 61 | + const peerDeps = pkgJson.peerDependencies || {}; |
| 62 | + expect(peerDeps[peerPkgName]).to.be.undefined; |
| 63 | + }); |
| 64 | +}); |
0 commit comments