Skip to content

Commit

Permalink
test: add checks based on git diff in it tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fpaul-1A committed Feb 2, 2024
1 parent f703e90 commit 26ea589
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 63 deletions.
14 changes: 12 additions & 2 deletions packages/@o3r/analytics/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
addImportToAppModule,
getDefaultExecSyncOptions,
getGitDiff,
packageManagerAdd,
packageManagerExec,
packageManagerInstall,
Expand All @@ -22,12 +23,16 @@ describe('new otter application with analytics', () => {
appFolderPath = await prepareTestEnv(appName, 'angular-with-o3r-core');
execAppOptions.cwd = appFolderPath;
});
test('should add analytics to existing application', () => {
test('should add analytics to existing application', async () => {
packageManagerExec(`ng add --skip-confirmation @o3r/analytics@${o3rVersion}`, execAppOptions);

packageManagerExec('ng g @o3r/core:component test-component --use-otter-analytics=false', execAppOptions);
packageManagerExec('ng g @o3r/analytics:add-analytics --path="src/components/test-component/test-component.component.ts"', execAppOptions);
addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');
await addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');

const diff = getGitDiff(appFolderPath);
expect(diff.modified).toContain('package.json');
expect(diff.added).toContain('src/components/test-component/test-component.analytics.ts');

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();
Expand All @@ -54,6 +59,11 @@ describe('new otter application with analytics', () => {
);
addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');

const diff = getGitDiff(execAppOptions.cwd as string);
expect(diff.all.some((file) => /projects[\\/]dont-modify-me/.test(file))).toBe(false);
expect(diff.modified).toContain('projects/test-app/package.json');
expect(diff.added).toContain('projects/test-app/src/components/test-component/test-component.analytics.ts');

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();
});
Expand Down
4 changes: 4 additions & 0 deletions packages/@o3r/apis-manager/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
getDefaultExecSyncOptions,
getGitDiff,
packageManagerExec,
packageManagerInstall,
packageManagerRun,
Expand All @@ -21,6 +22,9 @@ describe('new otter application with apis-manager', () => {
test('should add apis-manager to existing application', () => {
packageManagerExec(`ng add --skip-confirmation @o3r/apis-manager@${o3rVersion}`, execAppOptions);

const diff = getGitDiff(appFolderPath);
expect(diff.modified).toContain('package.json');

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();
});
Expand Down
4 changes: 4 additions & 0 deletions packages/@o3r/components/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
getDefaultExecSyncOptions,
getGitDiff,
packageManagerExec,
packageManagerInstall,
packageManagerRun,
Expand All @@ -21,6 +22,9 @@ describe('new otter application with components', () => {
test('should add components to existing application', () => {
packageManagerExec(`ng add --skip-confirmation @o3r/components@${o3rVersion} --enable-metadata-extract`, execAppOptions);

const diff = getGitDiff(appFolderPath);
expect(diff.modified).toContain('package.json');

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();
});
Expand Down
9 changes: 7 additions & 2 deletions packages/@o3r/configuration/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
addImportToAppModule,
getDefaultExecSyncOptions,
getGitDiff,
packageManagerExec,
packageManagerInstall,
packageManagerRun,
Expand All @@ -19,12 +20,16 @@ describe('new otter application with configuration', () => {
appFolderPath = await prepareTestEnv(appName, 'angular-with-o3r-core');
execAppOptions.cwd = appFolderPath;
});
test('should add configuration to existing application', () => {
test('should add configuration to existing application', async () => {
packageManagerExec(`ng add --skip-confirmation @o3r/configuration@${o3rVersion}`, execAppOptions);

packageManagerExec('ng g @o3r/core:component test-component --use-otter-config=false', execAppOptions);
packageManagerExec('ng g @o3r/configuration:add-config --path="src/components/test-component/test-component.component.ts"', execAppOptions);
addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');
await addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');

const diff = getGitDiff(appFolderPath);
expect(diff.modified).toContain('package.json');
expect(diff.added).toContain('src/components/test-component/test-component.config.ts');

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();
Expand Down
77 changes: 55 additions & 22 deletions packages/@o3r/core/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
addImportToAppModule,
getDefaultExecSyncOptions,
getGitDiff,
packageManagerExec,
packageManagerInstall,
packageManagerRun,
Expand All @@ -26,25 +27,25 @@ describe('new otter application', () => {
appFolderPath = await prepareTestEnv(appName, 'angular');
execAppOptions.cwd = appFolderPath;
});
test('should build empty app', () => {
test('should build empty app', async () => {
packageManagerExec(`ng add --skip-confirmation @o3r/core@${o3rVersion} --preset=all`, execAppOptions);
packageManagerExec(`ng add --skip-confirmation @o3r/analytics@${o3rVersion}`, execAppOptions);
expect(() => packageManagerInstall(execAppOptions)).not.toThrow();

packageManagerExec('ng g @o3r/core:store-entity-async --store-name="test-entity-async" --model-name="Bound" --model-id-prop-name="id"', execAppOptions);
addImportToAppModule(appFolderPath, 'TestEntityAsyncStoreModule', 'src/store/test-entity-async');
await addImportToAppModule(appFolderPath, 'TestEntityAsyncStoreModule', 'src/store/test-entity-async');

packageManagerExec('ng g @o3r/core:store-entity-sync --store-name="test-entity-sync" --model-name="Bound" --model-id-prop-name="id"', execAppOptions);
addImportToAppModule(appFolderPath, 'TestEntitySyncStoreModule', 'src/store/test-entity-sync');
await addImportToAppModule(appFolderPath, 'TestEntitySyncStoreModule', 'src/store/test-entity-sync');

packageManagerExec('ng g @o3r/core:store-simple-async --store-name="test-simple-async" --model-name="Bound"', execAppOptions);
addImportToAppModule(appFolderPath, 'TestSimpleAsyncStoreModule', 'src/store/test-simple-async');
await addImportToAppModule(appFolderPath, 'TestSimpleAsyncStoreModule', 'src/store/test-simple-async');

packageManagerExec('ng g @o3r/core:store-simple-sync --store-name="test-simple-sync"', execAppOptions);
addImportToAppModule(appFolderPath, 'TestSimpleSyncStoreModule', 'src/store/test-simple-sync');
await addImportToAppModule(appFolderPath, 'TestSimpleSyncStoreModule', 'src/store/test-simple-sync');

packageManagerExec('ng g @o3r/core:service test-service --feature-name="base"', execAppOptions);
addImportToAppModule(appFolderPath, 'TestServiceBaseModule', 'src/services/test-service');
await addImportToAppModule(appFolderPath, 'TestServiceBaseModule', 'src/services/test-service');

packageManagerExec('ng g @o3r/core:page test-page --app-routing-module-path="src/app/app-routing.module.ts"', execAppOptions);

Expand All @@ -58,7 +59,7 @@ describe('new otter application', () => {
'--use-rules-engine=false'
].join(' ');
packageManagerExec(`ng g @o3r/core:component test-component ${defaultOptions}`, execAppOptions);
addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');
await addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');

const advancedOptions = [
'--activate-dummy',
Expand All @@ -70,21 +71,33 @@ describe('new otter application', () => {
'--use-rules-engine=true'
].join(' ');
packageManagerExec(`ng g @o3r/core:component test-component-advanced ${advancedOptions}`, execAppOptions);
addImportToAppModule(appFolderPath, 'TestComponentAdvancedModule', 'src/components/test-component-advanced');
await addImportToAppModule(appFolderPath, 'TestComponentAdvancedModule', 'src/components/test-component-advanced');

packageManagerExec(`ng g @o3r/core:component test-add-context-component ${defaultOptions}`, execAppOptions);
packageManagerExec('ng g @o3r/core:add-context --path="src/components/test-add-context-component/test-add-context-component.component.ts"',
execAppOptions);
addImportToAppModule(appFolderPath, 'TestAddContextComponentModule', 'src/components/test-add-context-component');
await addImportToAppModule(appFolderPath, 'TestAddContextComponentModule', 'src/components/test-add-context-component');

packageManagerExec('ng g @schematics/angular:component test-ng-component', execAppOptions);
packageManagerExec('ng g @o3r/core:convert-component --path="src/app/test-ng-component/test-ng-component.component.ts"', execAppOptions);

packageManagerExec('ng g @o3r/testing:playwright-scenario --name=test-scenario', execAppOptions);
packageManagerExec('ng g @o3r/testing:playwright-sanity --name=test-sanity', execAppOptions);

const diff = getGitDiff(execAppOptions.cwd as string);

// Expect created files inside `test-app` project
expect(diff.added.filter((file) => /e2e-playwright/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /src[\\/]app/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /src[\\/]components/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /src[\\/]environments/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /src[\\/]services/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /src[\\/]store/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /src[\\/]styling/.test(file)).length).toBeGreaterThan(0);

expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();

// should pass the e2e tests
packageManagerExec('ng g @o3r/testing:playwright-scenario --name=test-scenario', execAppOptions);
packageManagerExec('ng g @o3r/testing:playwright-sanity --name=test-sanity', execAppOptions);
spawn(`npx http-server -p ${devServerPort} ./dist/browser`, [], {
...execAppOptions,
shell: true,
Expand All @@ -109,11 +122,12 @@ describe('new otter application', () => {

describe('monorepo', () => {
beforeAll(async () => {
// TODO Should not start the test with @o3r/core already installed
const workspacePath = await prepareTestEnv(`${appName}-monorepo`, 'angular-monorepo-with-o3r-core');
appFolderPath = join(workspacePath, 'projects', 'test-app');
execAppOptions.cwd = workspacePath;
});
test('should build empty app', () => {
test('should build empty app', async () => {

const projectName = '--project-name=test-app';
packageManagerExec(`ng add --skip-confirmation @o3r/core@${o3rVersion} --preset=all ${projectName}`, execAppOptions);
Expand All @@ -123,31 +137,31 @@ describe('new otter application', () => {
`ng g @o3r/core:store-entity-async --store-name="test-entity-async" --model-name="Bound" --model-id-prop-name="id" ${projectName}`,
execAppOptions
);
addImportToAppModule(appFolderPath, 'TestEntityAsyncStoreModule', 'src/store/test-entity-async');
await addImportToAppModule(appFolderPath, 'TestEntityAsyncStoreModule', 'src/store/test-entity-async');

packageManagerExec(
`ng g @o3r/core:store-entity-sync --store-name="test-entity-sync" --model-name="Bound" --model-id-prop-name="id" ${projectName}`,
execAppOptions
);
addImportToAppModule(appFolderPath, 'TestEntitySyncStoreModule', 'src/store/test-entity-sync');
await addImportToAppModule(appFolderPath, 'TestEntitySyncStoreModule', 'src/store/test-entity-sync');

packageManagerExec(
`ng g @o3r/core:store-simple-async --store-name="test-simple-async" --model-name="Bound" ${projectName}`,
execAppOptions
);
addImportToAppModule(appFolderPath, 'TestSimpleAsyncStoreModule', 'src/store/test-simple-async');
await addImportToAppModule(appFolderPath, 'TestSimpleAsyncStoreModule', 'src/store/test-simple-async');

packageManagerExec(
`ng g @o3r/core:store-simple-sync --store-name="test-simple-sync" ${projectName}`,
execAppOptions
);
addImportToAppModule(appFolderPath, 'TestSimpleSyncStoreModule', 'src/store/test-simple-sync');
await addImportToAppModule(appFolderPath, 'TestSimpleSyncStoreModule', 'src/store/test-simple-sync');

packageManagerExec(
`ng g @o3r/core:service test-service --feature-name="base" ${projectName}`,
execAppOptions
);
addImportToAppModule(appFolderPath, 'TestServiceBaseModule', 'src/services/test-service');
await addImportToAppModule(appFolderPath, 'TestServiceBaseModule', 'src/services/test-service');

packageManagerExec(
`ng g @o3r/core:page test-page --app-routing-module-path="projects/test-app/src/app/app-routing.module.ts" ${projectName}`,
Expand All @@ -167,7 +181,7 @@ describe('new otter application', () => {
`ng g @o3r/core:component test-component ${defaultOptions} ${projectName}`,
execAppOptions
);
addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');
await addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');

const advancedOptions = [
'--activate-dummy',
Expand All @@ -182,7 +196,7 @@ describe('new otter application', () => {
`ng g @o3r/core:component test-component-advanced ${advancedOptions} ${projectName}`,
execAppOptions
);
addImportToAppModule(appFolderPath, 'TestComponentAdvancedModule', 'src/components/test-component-advanced');
await addImportToAppModule(appFolderPath, 'TestComponentAdvancedModule', 'src/components/test-component-advanced');

packageManagerExec(
`ng g @o3r/core:component test-add-context-component ${defaultOptions} ${projectName}`,
Expand All @@ -192,7 +206,7 @@ describe('new otter application', () => {
'ng g @o3r/core:add-context --path="projects/test-app/src/components/test-add-context-component/test-add-context-component.component.ts"',
execAppOptions
);
addImportToAppModule(appFolderPath, 'TestAddContextComponentModule', 'src/components/test-add-context-component');
await addImportToAppModule(appFolderPath, 'TestAddContextComponentModule', 'src/components/test-add-context-component');

packageManagerExec(
'ng g @schematics/angular:component test-ng-component --project=test-app',
Expand All @@ -203,11 +217,30 @@ describe('new otter application', () => {
execAppOptions
);

packageManagerExec(`ng g @o3r/testing:playwright-scenario --name=test-scenario ${projectName}`, execAppOptions);
packageManagerExec(`ng g @o3r/testing:playwright-sanity --name=test-sanity ${projectName}`, execAppOptions);

const diff = getGitDiff(execAppOptions.cwd as string);

// Expect no file modified inside 'dont-modify-me' project
expect(diff.all.filter((file) => /projects[\\/]dont-modify-me/.test(file)).length).toBe(0);

// Expect no file created outside 'test-app' project
expect(diff.added.filter((file) => !/projects[\\/]test-app/.test(file)).length).toBe(0);

// Expect created files inside `test-app` project
expect(diff.added.filter((file) => /projects[\\/]test-app[\\/]e2e-playwright/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /projects[\\/]test-app[\\/]src[\\/]app/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /projects[\\/]test-app[\\/]src[\\/]components/.test(file)).length).toBeGreaterThan(0);
// TODO Should not start the test with @o3r/core already installed
// expect(diff.added.filter((file) => /projects[\\/]test-app[\\/]src[\\/]environments/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /projects[\\/]test-app[\\/]src[\\/]services/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /projects[\\/]test-app[\\/]src[\\/]store/.test(file)).length).toBeGreaterThan(0);
expect(diff.added.filter((file) => /projects[\\/]test-app[\\/]src[\\/]styling/.test(file)).length).toBeGreaterThan(0);

expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();

// should pass the e2e tests
packageManagerExec(`ng g @o3r/testing:playwright-scenario --name=test-scenario ${projectName}`, execAppOptions);
packageManagerExec(`ng g @o3r/testing:playwright-sanity --name=test-sanity ${projectName}`, execAppOptions);
spawn(`npx http-server -p ${devServerPort} ./projects/test-app/dist/browser`, [], {
...execAppOptions,
shell: true,
Expand Down
4 changes: 4 additions & 0 deletions packages/@o3r/extractors/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
getDefaultExecSyncOptions,
getGitDiff,
packageManagerExec,
packageManagerInstall,
packageManagerRun,
Expand All @@ -21,6 +22,9 @@ describe('new otter application with extractors', () => {
test('should add extractors to existing application', () => {
packageManagerExec(`ng add --skip-confirmation @o3r/extractors@${o3rVersion}`, execAppOptions);

const diff = getGitDiff(appFolderPath);
expect(diff.modified).toContain('package.json');

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();
});
Expand Down
10 changes: 8 additions & 2 deletions packages/@o3r/localization/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
addImportToAppModule,
getDefaultExecSyncOptions,
getGitDiff,
packageManagerExec,
packageManagerInstall,
packageManagerRun,
Expand All @@ -19,14 +20,19 @@ describe('new otter application with localization', () => {
appFolderPath = await prepareTestEnv(appName, 'angular-with-o3r-core');
execAppOptions.cwd = appFolderPath;
});
test('should add localization to existing application', () => {
test('should add localization to existing application', async () => {
packageManagerExec(`ng add --skip-confirmation @o3r/localization@${o3rVersion}`, execAppOptions);

packageManagerExec('ng g @o3r/core:component test-component --use-localization=false', execAppOptions);
packageManagerExec(
'ng g @o3r/localization:add-localization --activate-dummy --path="src/components/test-component/test-component.component.ts"',
execAppOptions);
addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');
await addImportToAppModule(appFolderPath, 'TestComponentModule', 'src/components/test-component');

const diff = getGitDiff(appFolderPath);
expect(diff.modified).toContain('package.json');
expect(diff.added).toContain('src/components/test-component/test-component.localization.json');
expect(diff.added).toContain('src/components/test-component/test-component.translation.ts');

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRun('build', execAppOptions)).not.toThrow();
Expand Down
Loading

0 comments on commit 26ea589

Please sign in to comment.