diff --git a/e2e/harmony/app.e2e.ts b/e2e/harmony/app.e2e.ts index 2327dfa02def..1e0bc794db11 100644 --- a/e2e/harmony/app.e2e.ts +++ b/e2e/harmony/app.e2e.ts @@ -1,8 +1,48 @@ import chai, { expect } from 'chai'; +import { join } from 'path'; import Helper from '../../src/e2e-helper/e2e-helper'; chai.use(require('chai-fs')); +const ENV_POLICY = { + peers: [ + { + name: 'react', + version: '^18.0.0', + supportedRange: '^17.0.0 || ^18.0.0', + }, + { + name: 'react-dom', + version: '^18.0.0', + supportedRange: '^17.0.0 || ^18.0.0', + }, + { + name: 'graphql', + version: '14.7.0', + supportedRange: '^14.7.0', + }, + { + name: '@mdx-js/react', + version: '1.6.22', + supportedRange: '^1.6.22', + }, + { + name: '@teambit/mdx.ui.mdx-scope-context', + version: '0.0.496', + supportedRange: '^0.0.496', + }, + ], +}; + +export const REACT_CJS_APP = `module.exports.default = { + name: 'my-app', + entry: [require.resolve('./my-app.app-root')], + prerender: { + routes: ['/'] + } +}; +` + describe('app command', function () { this.timeout(0); let helper: Helper; @@ -13,17 +53,45 @@ describe('app command', function () { helper.scopeHelper.destroy(); }); describe('app run', () => { - before(() => { - helper.scopeHelper.setNewLocalAndRemoteScopes({ addRemoteScopeAsDefaultScope: false }); - helper.command.create('express-app', 'my-app'); - helper.command.compile(); - helper.command.install(); - helper.bitJsonc.addKeyVal('my-scope/my-app', {}); + describe('core express app', () => { + before(() => { + helper.scopeHelper.setNewLocalAndRemoteScopes({ addRemoteScopeAsDefaultScope: false }); + helper.command.create('express-app', 'my-app'); + helper.command.compile(); + helper.command.install(); + helper.bitJsonc.addKeyVal('my-scope/my-app', {}); + }); + // previously, it was supporting only app-name + it('should support app-id', () => { + const output = helper.general.runWithTryCatch('bit app run my-scope/my-app'); + expect(output).to.have.string('my-scope/my-app app is running on'); + }); }); - // previously, it was supporting only app-name - it('should support app-id', () => { - const output = helper.general.runWithTryCatch('bit app run my-scope/my-app'); - expect(output).to.have.string('my-scope/my-app app is running on'); + describe('env apps API', () => { + describe('React app', () => { + before(() => { + helper.scopeHelper.setNewLocalAndRemoteScopes({ addRemoteScopeAsDefaultScope: false }); + const envId = 'my-scope/react-based-env'; + // Replace with new app template of the new react env when it's ready + helper.command.create('react-app', 'my-app'); + helper.fs.writeFile(join('my-scope', 'my-app', 'my-app.react-18-app.cjs'), REACT_CJS_APP); + helper.fs.deletePath(join('my-scope', 'my-app','my-app.react-app.ts')) + helper.env.setCustomNewEnv(undefined, undefined, { policy: ENV_POLICY }); + helper.command.setEnv('my-app', envId); + helper.command.install('react-router-dom@6.4.3'); + helper.bitJsonc.addKeyVal('my-scope/my-app', {}); + helper.bitJsonc.addKeyVal('teambit.harmony/application', {envs: [envId]}); + }); + it('should show the app', () => { + const output = helper.command.listApps(); + expect(output).to.have.string('my-app'); + expect(output).to.have.string('my-scope/my-app'); + }); + it('should run the app', () => { + const output = helper.general.runWithTryCatch('bit app run my-app'); + expect(output).to.have.string('my-app app is running on'); + }); + }); }); }); }); diff --git a/src/e2e-helper/e2e-command-helper.ts b/src/e2e-helper/e2e-command-helper.ts index 2a093efa2ba7..5fd2355bab13 100644 --- a/src/e2e-helper/e2e-command-helper.ts +++ b/src/e2e-helper/e2e-command-helper.ts @@ -655,6 +655,9 @@ export default class CommandHelper { new(templateName: string, flags = '', workspaceName = 'my-workspace', cwd = this.scopes.localPath) { return this.runCmd(`bit new ${templateName} ${workspaceName} ${flags}`, cwd); } + listApps() { + return this.runCmd('bit app list'); + } runApp(name: string) { return this.runCmd(`bit app run ${name}`); } diff --git a/src/e2e-helper/e2e-env-helper.ts b/src/e2e-helper/e2e-env-helper.ts index 5d20e9f4cd52..cfc35fa954ef 100644 --- a/src/e2e-helper/e2e-env-helper.ts +++ b/src/e2e-helper/e2e-env-helper.ts @@ -240,7 +240,8 @@ export default class EnvHelper { * @param extensionsBaseFolder * @returns */ - setCustomNewEnv(extensionsBaseFolder = 'react-based-env', basePackages: string[] = ['@teambit/react.react-env'], envJsoncOptions: GenerateEnvJsoncOptions): string { + // TODO: remove the 0.0.22 version from here. it's here becasue of temporary issue with the regsitry that bring v0.0.20 when no specific version is specified + setCustomNewEnv(extensionsBaseFolder = 'react-based-env', basePackages: string[] = ['@teambit/react.react-env@0.0.22'], envJsoncOptions: GenerateEnvJsoncOptions): string { this.fixtures.copyFixtureExtensions(extensionsBaseFolder); this.command.addComponent(extensionsBaseFolder); this.fixtures.generateEnvJsoncFile(extensionsBaseFolder, envJsoncOptions); diff --git a/src/e2e-helper/e2e-fs-helper.ts b/src/e2e-helper/e2e-fs-helper.ts index 89710e9c86e9..d7199a8077b5 100644 --- a/src/e2e-helper/e2e-fs-helper.ts +++ b/src/e2e-helper/e2e-fs-helper.ts @@ -91,6 +91,14 @@ export default class FsHelper { fs.outputFileSync(absPath, `\n${content}`); } + changeFileName(filePath: string, newFilePath: string, basePath = this.scopes.localPath) { + const absPath = basePath ? path.join(basePath, filePath) : filePath; + const absNewPath = basePath ? path.join(basePath, newFilePath) : newFilePath; + const content = fs.readFileSync(absPath); + fs.outputFileSync(absNewPath, content); + fs.removeSync(absPath); + } + deletePath(relativePathToLocalScope: string) { return fs.removeSync(path.join(this.scopes.localPath, relativePathToLocalScope)); }