Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Introduce yarn run test:full (#51)
Browse files Browse the repository at this point in the history
* Update dependencies

* Only run fast tests with `yarn test`

* Use expect().includeAllMembers()

* Remove timeouts

* Improve error handling with verbose flag

* Change label to E2E
  • Loading branch information
Florian Richter authored Jan 14, 2020
1 parent 0a4baeb commit b8a8765
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ jobs:
- name: Install Dependencies
run: yarn install --frozen-lockfile --ignore-engines
- name: Run tests
run: yarn test
run: yarn run test:full
env:
CI: true
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"cli-ux": "^5.4.1",
"execa": "^3.4.0",
"fast-glob": "^3.1.1",
"handlebars": "^4.5.3",
"handlebars": "^4.6.0",
"js-yaml": "^3.13.1",
"listr": "^0.14.3",
"rimraf": "^3.0.0",
Expand All @@ -33,16 +33,16 @@
"@types/jest": "^24.0.25",
"@types/js-yaml": "^3.12.1",
"@types/listr": "^0.14.2",
"@types/node": "^12.12.24",
"@types/node": ">=10.0.0",
"@types/rimraf": "^2.0.3",
"fs-extra": "^8.1.0",
"globby": "^10.0.2",
"jest": "^24.9.0",
"jest-extended": "^0.11.2",
"np": "^5.2.1",
"prettier": "^1.19.1",
"ts-jest": "^24.2.0",
"ts-node": "^8.5.4",
"ts-jest": "^24.3.0",
"ts-node": "^8.6.0",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.7.4"
Expand Down Expand Up @@ -90,7 +90,8 @@
"prepack": "rm -rf lib && tsc -b && cp -R src/templates lib/ && oclif-dev manifest && oclif-dev readme",
"postpack": "rm -f oclif.manifest.json",
"pretest": "rm -rf test/test-output/*-spec/ && npm run lint && tsc -b",
"test": "jest",
"test": "jest --testNamePattern=\"^((?!\\[E2E\\]).)*$\"",
"test:full": "jest",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
"test:watch-debug": "node --inspect-brk node_modules/.bin/jest --watch --runInBand",
"version": "oclif-dev readme && git add README.md"
Expand Down
14 changes: 8 additions & 6 deletions src/commands/add-cds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ export default class AddCds extends Command {
title: 'Creating files',
task: async () => {
const copyDescriptors = getCopyDescriptors(projectDir, getTemplatePaths(['add-cds']));
await findConflicts(copyDescriptors, flags.force).catch(e => this.error(e, { exit: 11 }));
await findConflicts(copyDescriptors, flags.force).catch(e => this.error(flags.verbose ? e.stack : e.message, { exit: 11 }));
await copyFiles(copyDescriptors, options);
}
},
{
title: 'Adding dependencies to package.json',
task: async () => modifyPackageJson({ projectDir, force: flags.force, addCds: true }).catch(e => this.error(e, { exit: 12 }))
task: async () =>
modifyPackageJson({ projectDir, force: flags.force, addCds: true }).catch(e =>
this.error(flags.verbose ? e.stack : e.message, { exit: 12 })
)
},
{
title: 'Installing dependencies',
task: async () =>
installDependencies(projectDir, flags.verbose).catch(e => this.error(`Error during npm install: ${e.message}`, { exit: 13 })),
task: async () => installDependencies(projectDir, flags.verbose).catch(e => this.error(flags.verbose ? e.stack : e.message, { exit: 13 })),
enabled: () => !flags.skipInstall
},
{
Expand All @@ -77,8 +79,8 @@ export default class AddCds extends Command {
await tasks.run();

this.printSuccessMessage();
} catch (error) {
this.error(error, { exit: 1 });
} catch (e) {
this.error(flags.verbose ? e.stack : e.message, { exit: 1 });
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export default class Init extends Command {
if (isScaffold) {
await buildScaffold(projectDir, flags.verbose, flags.addCds);
}
const options = await this.getOptions(projectDir, isScaffold ? 'npm run start:prod' : flags.startCommand, flags.projectName);
const options = await this.getOptions(projectDir, isScaffold ? 'npm run start:prod' : flags.startCommand, flags.projectName).catch(e =>
this.error(flags.verbose ? e.stack : e.message, { exit: 10 })
);

await usageAnalytics(projectDir, flags.analytics, flags.analyticsSalt);

Expand All @@ -105,7 +107,7 @@ export default class Init extends Command {
title: 'Creating files',
task: async () => {
const copyDescriptors = getCopyDescriptors(projectDir, getTemplatePaths(this.getTemplateNames(isScaffold, flags.addCds)));
await findConflicts(copyDescriptors, flags.force).catch(e => this.error(e, { exit: 11 }));
await findConflicts(copyDescriptors, flags.force).catch(e => this.error(flags.verbose ? e.stack : e.message, { exit: 11 }));
await copyFiles(copyDescriptors, options);
}
},
Expand All @@ -118,13 +120,12 @@ export default class Init extends Command {
title: 'Adding dependencies to package.json',
task: async () =>
modifyPackageJson({ projectDir, isScaffold, frontendScripts: flags.frontendScripts, force: flags.force, addCds: flags.addCds }).catch(e =>
this.error(e, { exit: 12 })
this.error(flags.verbose ? e.stack : e.message, { exit: 12 })
)
},
{
title: 'Installing dependencies',
task: async () =>
installDependencies(projectDir, flags.verbose).catch(e => this.error(`Error during npm install: ${e.message}`, { exit: 13 })),
task: async () => installDependencies(projectDir, flags.verbose).catch(e => this.error(flags.verbose ? e.stack : e.message, { exit: 13 })),
enabled: () => !flags.skipInstall
},
{
Expand All @@ -137,7 +138,7 @@ export default class Init extends Command {

this.printSuccessMessage(isScaffold, flags.addCds);
} catch (error) {
this.error(error, { exit: 1 });
this.error(flags.verbose ? error.stack : error.message, { exit: 1 });
}
}

Expand All @@ -158,7 +159,7 @@ export default class Init extends Command {
}

private async getOptions(projectDir: string, startCommand?: string, projectName?: string) {
const { name, scripts } = await parsePackageJson(projectDir).catch(err => this.error(err, { exit: 10 }));
const { name, scripts } = await parsePackageJson(projectDir);

const options: { [key: string]: string } = {
projectName:
Expand Down
12 changes: 2 additions & 10 deletions test/add-approuter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ describe('Add Approuter', () => {
expect(files).toContain('approuter');

const approuterFiles = fs.readdirSync(path.resolve(projectDir, 'approuter'));
expect(approuterFiles).toContain('.npmrc');
expect(approuterFiles).toContain('manifest.yml');
expect(approuterFiles).toContain('package.json');
expect(approuterFiles).toContain('xs-app.json');
expect(approuterFiles).toContain('xs-security.json');
expect(approuterFiles).toIncludeAllMembers(['.npmrc', 'manifest.yml', 'package.json', 'xs-app.json', 'xs-security.json']);
});

it('should add necessary files to an existing project', async () => {
Expand All @@ -52,11 +48,7 @@ describe('Add Approuter', () => {
expect(files).toContain('approuter');

const approuterFiles = fs.readdirSync(path.resolve(projectDir, 'approuter'));
expect(approuterFiles).toContain('.npmrc');
expect(approuterFiles).toContain('manifest.yml');
expect(approuterFiles).toContain('package.json');
expect(approuterFiles).toContain('xs-app.json');
expect(approuterFiles).toContain('xs-security.json');
expect(approuterFiles).toIncludeAllMembers(['.npmrc', 'manifest.yml', 'package.json', 'xs-app.json', 'xs-security.json']);
});

it('should detect and fail if there are conflicts', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/add-cds.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Add CDS', () => {
expect(dbFiles).toContain('data-model.cds');
const srvFiles = fs.readdirSync(path.resolve(projectDir, 'srv'));
expect(srvFiles).toContain('cat-service.cds');
}, 15000);
});

it('should detect and fail if there are conflicts', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'add-cds-conflicts');
Expand All @@ -53,5 +53,5 @@ describe('Add CDS', () => {
fs.writeFileSync(path.resolve(projectDir, 'db', 'data-model.cds'), 'some text', 'utf8');

await expect(AddCds.run([projectDir, '--skipInstall'])).rejects.toMatchSnapshot();
}, 10000);
});
});
18 changes: 7 additions & 11 deletions test/add-cx-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ describe('Add CX Server', () => {
expect(files).toContain('cx-server');

const approuterFiles = fs.readdirSync(path.resolve(projectDir, 'cx-server'));
expect(approuterFiles).toContain('cx-server');
expect(approuterFiles).toContain('server.cfg');
}, 30000);
expect(approuterFiles).toIncludeAllMembers(['cx-server', 'server.cfg']);
});

it('should add the necessary files on windows', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'add-cx-server');
Expand All @@ -36,10 +35,8 @@ describe('Add CX Server', () => {
expect(files).toContain('cx-server');

const approuterFiles = fs.readdirSync(path.resolve(projectDir, 'cx-server'));
expect(approuterFiles).toContain('cx-server');
expect(approuterFiles).toContain('cx-server.bat');
expect(approuterFiles).toContain('server.cfg');
}, 30000);
expect(approuterFiles).toIncludeAllMembers(['cx-server', 'cx-server.bat', 'server.cfg']);
});

it('should add necessary files to an existing project', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'add-cx-server-to-existing-project');
Expand All @@ -52,9 +49,8 @@ describe('Add CX Server', () => {
expect(files).toContain('cx-server');

const approuterFiles = fs.readdirSync(path.resolve(projectDir, 'cx-server'));
expect(approuterFiles).toContain('cx-server');
expect(approuterFiles).toContain('server.cfg');
}, 30000);
expect(approuterFiles).toIncludeAllMembers(['cx-server', 'server.cfg']);
});

it('should detect and fail if there are conflicts', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'add-cx-server-conflicts');
Expand All @@ -63,5 +59,5 @@ describe('Add CX Server', () => {
fs.createFileSync(path.resolve(projectDir, 'cx-server', 'cx-server'));

await expect(AddCxServer.run([projectDir])).rejects.toMatchSnapshot();
}, 30000);
});
});
26 changes: 11 additions & 15 deletions test/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Init', () => {
fs.removeSync(testOutputDir);
});

it('should create a new project with the necessary files', async () => {
it('[E2E] should create a new project with the necessary files', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'full-init');
await Init.run([projectDir, '--projectName=testingApp', '--buildScaffold', '--no-analytics']);

Expand All @@ -43,7 +43,7 @@ describe('Init', () => {
expect(fs.readdirSync(path.resolve(reportsPath, 'coverage-reports', 'backend-integration')).length).toBeGreaterThan(1);
}, 240000);

it('should create a new project with the necessary files when adding cds', async () => {
it('[E2E] should create a new project with the necessary files when adding cds', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'full-init-cds');
await Init.run([projectDir, '--projectName=testingApp', '--buildScaffold', '--no-analytics', '--addCds']);

Expand All @@ -69,7 +69,7 @@ describe('Init', () => {
expect(fs.existsSync(path)).toBe(true);
});
expect(fs.existsSync(path.resolve(projectDir, 'test'))).toBe(false);
}, 10000);
});

it('should add necessary files to an existing project when adding cds', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'add-to-existing');
Expand All @@ -82,7 +82,7 @@ describe('Init', () => {
.forEach(path => {
expect(fs.existsSync(path)).toBe(true);
});
}, 10000);
});

it('init should detect and fail if there are conflicts', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'detect-conflicts');
Expand All @@ -92,7 +92,7 @@ describe('Init', () => {
await expect(
Init.run([projectDir, '--projectName=testingApp', '--startCommand="npm start"', '--skipInstall', '--no-analytics'])
).rejects.toMatchSnapshot();
}, 10000);
});

it('should add to .gitignore if there is one', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'add-to-gitignore');
Expand All @@ -105,11 +105,9 @@ describe('Init', () => {
.split('\n')
.filter(entry => entry !== '');

expect(gitignoreEntries).toContain('credentials.json');
expect(gitignoreEntries).toContain('/s4hana_pipeline');
expect(gitignoreEntries).toContain('/deployment');
expect(gitignoreEntries).toIncludeAllMembers(['credentials.json', '/s4hana_pipeline', '/deployment']);
expect(gitignoreEntries.length).toBeGreaterThan(29);
}, 10000);
});

it('should show a warning if the project is not using git', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'warn-on-no-git');
Expand All @@ -128,7 +126,7 @@ describe('Init', () => {
' /deployment'
);
expect(getWarnings).toHaveBeenCalled();
}, 10000);
});

it('should add our scripts and dependencies to the package.json', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'add-scripts-and-dependencies');
Expand All @@ -145,10 +143,8 @@ describe('Init', () => {

expect(dependencies).toContain('@sap/cloud-sdk-core');
expect(devDependencies).toContain('@sap/cloud-sdk-test-util');
['ci-build', 'ci-package', 'ci-backend-unit-test', 'ci-frontend-unit-test', 'ci-integration-test', 'ci-e2e'].forEach(script =>
expect(scripts).toContain(script)
);
}, 10000);
expect(scripts).toIncludeAllMembers(['ci-build', 'ci-package', 'ci-backend-unit-test', 'ci-frontend-unit-test', 'ci-integration-test', 'ci-e2e']);
});

it('should add the analytics file', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'add-to-gitignore');
Expand All @@ -173,5 +169,5 @@ describe('Init', () => {
await Init.run([projectDir, '--projectName=testingApp', '--startCommand="npm start"', '--skipInstall', '--no-analytics']);

expect(JSON.parse(fs.readFileSync(`${projectDir}/sap-cloud-sdk-analytics.json`, 'utf8'))).toEqual({ enabled: false });
}, 10000);
});
});
2 changes: 1 addition & 1 deletion test/package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Package', () => {
expect(fs.readdirSync(path.resolve(projectDir, 'deployment'))).toEqual(['README.md']);
});

it('should install productive dependencies only', async () => {
it('[E2E] should install productive dependencies only', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'productive-dependencies');
fs.copySync(nestAppDir, projectDir, { recursive: true });
await Package.run([projectDir]);
Expand Down
2 changes: 1 addition & 1 deletion test/utils/__snapshots__/scaffold.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Scaffold Utils should build the scaffold 1`] = `
exports[`Scaffold Utils [E2E] should build the scaffold 1`] = `
Array [
".git",
".gitignore",
Expand Down
10 changes: 3 additions & 7 deletions test/utils/git-ignore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ describe('Git Ignore Utils', () => {
modifyGitIgnore(projectDir, false);

const gitIgnoreContent = fs.readFileSync(`${projectDir}/.gitignore`, { encoding: 'utf8' }).split('\n');
expect(gitIgnoreContent).toContain('/s4hana_pipeline');
expect(gitIgnoreContent).toContain('credentials.json');
expect(gitIgnoreContent).toIncludeAllMembers(['/s4hana_pipeline', 'credentials.json']);
});

it('should add cds paths to empty git ignore', () => {
Expand All @@ -32,8 +31,7 @@ describe('Git Ignore Utils', () => {
modifyGitIgnore(projectDir, true);

const gitIgnoreContent = fs.readFileSync(`${projectDir}/.gitignore`, { encoding: 'utf8' }).split('\n');
expect(gitIgnoreContent).toContain('gen/');
expect(gitIgnoreContent).toContain('*.db');
expect(gitIgnoreContent).toIncludeAllMembers(['gen/', '*.db']);
});

it('should add paths to existing git ignore', () => {
Expand All @@ -49,9 +47,7 @@ describe('Git Ignore Utils', () => {
modifyGitIgnore(projectDir, false);

const gitIgnoreContent = fs.readFileSync(`${projectDir}/.gitignore`, { encoding: 'utf8' }).split('\n');
expect(gitIgnoreContent).toContain('/s4hana_pipeline');
expect(gitIgnoreContent).toContain('myPath');
expect(gitIgnoreContent).toContain('credentials.json');
expect(gitIgnoreContent).toIncludeAllMembers(['/s4hana_pipeline', 'myPath', 'credentials.json']);
});

it('warn if there is no git ignore', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/utils/scaffold.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Scaffold Utils', () => {
expect(await shouldBuildScaffold(projectDir, false)).toBe(false);
});

it('should build the scaffold', async () => {
it('[E2E] should build the scaffold', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'build-scaffold');

await buildScaffold(projectDir, false, false);
Expand Down
Loading

0 comments on commit b8a8765

Please sign in to comment.