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

Ignore artifacts of previously cancelled test runs #31

Merged
merged 4 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
modulePathIgnorePatterns: ['<rootDir>/lib', '<rootDir>/bin', '<rootDir>/tmp', '<rootDir>/test/nest', '<rootDir>/test/express'],
roots: ["test"]
modulePathIgnorePatterns: [
'<rootDir>/lib',
'<rootDir>/bin',
'<rootDir>/tmp',
'<rootDir>/test/nest',
'<rootDir>/test/express',
'<rootDir>/test/[^/]*/[^/]*-spec'
],
roots: ['test']
};
7 changes: 6 additions & 1 deletion src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export default class Init extends Command {
analyticsSalt: flags.string({
hidden: true,
description: 'Set salt for analytics. This should only be used for CI builds.'
}),
skipInstall: flags.boolean({
hidden: true,
description: 'Skip installing npm dependencies. If you use this, make sure to install manually afterwards.'
})
};

Expand Down Expand Up @@ -121,7 +125,8 @@ export default class Init extends Command {
},
{
title: 'Installing dependencies',
task: () => installDependencies(projectDir, verbose).catch(e => this.error(`Error during npm install: ${e.message}`, { exit: 13 }))
task: () => installDependencies(projectDir, verbose).catch(e => this.error(`Error during npm install: ${e.message}`, { exit: 13 })),
enabled: () => !flags.skipInstall
},
{
title: 'Modifying `.gitignore`',
Expand Down
41 changes: 28 additions & 13 deletions test/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,41 @@ describe('Init', () => {
const projectDir = getCleanProjectDir('add-to-existing');
fs.copySync(expressAppDir, projectDir, { recursive: true });

await Init.run(['--projectName=testingApp', '--startCommand="npm start"', `--projectDir=${projectDir}`, '--no-analytics', '--force']);
await Init.run([
'--projectName=testingApp',
'--startCommand="npm start"',
`--projectDir=${projectDir}`,
'--no-analytics',
'--skipInstall',
'--force'
]);

['.npmrc', 'credentials.json', 'systems.json', 'manifest.yml']
.map(file => path.resolve(projectDir, file))
.forEach(path => {
expect(fs.existsSync(path)).toBe(true);
});
expect(fs.existsSync(path.resolve(projectDir, 'test'))).toBe(false);
}, 60000);
}, 10000);

it('init should detect and fail if there are conflicts', async () => {
const projectDir = getCleanProjectDir('detect-conflicts');
fs.copySync(nestAppDir, projectDir, { recursive: true });
fs.createFileSync(`${projectDir}/.npmrc`);

await Init.run(['--projectName=testingApp', '--startCommand="npm start"', `--projectDir=${projectDir}`, '--no-analytics']);
await Init.run(['--projectName=testingApp', '--startCommand="npm start"', `--projectDir=${projectDir}`, '--skipInstall', '--no-analytics']);

expect(error).toHaveBeenCalledWith(
'A file with the name ".npmrc" already exists. If you want to overwrite it, rerun the command with `--force`.',
{ exit: 1 }
);
}, 60000);
}, 10000);

it('should add to .gitignore if there is one', async () => {
const projectDir = getCleanProjectDir('add-to-gitignore');
fs.copySync(nestAppDir, projectDir, { recursive: true });

await Init.run(['--projectName=testingApp', '--startCommand="npm start"', `--projectDir=${projectDir}`, '--no-analytics']);
await Init.run(['--projectName=testingApp', '--startCommand="npm start"', `--projectDir=${projectDir}`, '--skipInstall', '--no-analytics']);

const gitignoreEntries = fs
.readFileSync(`${projectDir}/.gitignore`, 'utf8')
Expand All @@ -116,25 +123,32 @@ describe('Init', () => {
expect(gitignoreEntries).toContain('/s4hana_pipeline');
expect(gitignoreEntries).toContain('/deployment');
expect(gitignoreEntries.length).toBeGreaterThan(29);
}, 60000);
}, 10000);

it('should show a warning if the project is not using git', async () => {
const projectDir = getCleanProjectDir('warn-on-no-git');

fs.createFileSync(path.resolve(projectDir, 'package.json'));
fs.writeFileSync(path.resolve(projectDir, 'package.json'), JSON.stringify({ name: 'project' }), 'utf8');

await Init.run(['--projectName=testingApp', '--startCommand="npm start"', `--projectDir=${projectDir}`, '--no-analytics']);
await Init.run(['--projectName=testingApp', '--startCommand="npm start"', `--projectDir=${projectDir}`, '--skipInstall', '--no-analytics']);

expect(warn).toHaveBeenCalledWith('No .gitignore file found!');
}, 60000);
}, 10000);

it('should add our scripts and dependencies to the package.json', async () => {
const projectDir = getCleanProjectDir('add-scripts-and-dependencies');
fs.createFileSync(path.resolve(projectDir, 'package.json'));
fs.writeFileSync(path.resolve(projectDir, 'package.json'), JSON.stringify({ name: 'project' }), 'utf8');

await Init.run(['--projectName=testingApp', '--startCommand="npm start"', '--frontendScripts', `--projectDir=${projectDir}`, '--no-analytics']);
await Init.run([
'--projectName=testingApp',
'--startCommand="npm start"',
'--frontendScripts',
`--projectDir=${projectDir}`,
'--skipInstall',
'--no-analytics'
]);

const packageJson = JSON.parse(fs.readFileSync(path.resolve(projectDir, 'package.json'), 'utf8'));

Expand All @@ -147,7 +161,7 @@ describe('Init', () => {
['ci-build', 'ci-package', 'ci-backend-unit-test', 'ci-frontend-unit-test', 'ci-integration-test', 'ci-e2e'].forEach(script =>
expect(scripts).toContain(script)
);
}, 60000);
}, 10000);

it('should add the analytics file', async () => {
const projectDir = getCleanProjectDir('add-to-gitignore');
Expand All @@ -157,19 +171,20 @@ describe('Init', () => {
'--projectName=testingApp',
'--startCommand="npm start"',
`--projectDir=${projectDir}`,
'--skipInstall',
'--analytics',
'--analyticsSalt=SAPCLOUDSDK4LIFE'
]);

expect(JSON.parse(fs.readFileSync(`${projectDir}/sap-cloud-sdk-analytics.json`, 'utf8'))).toEqual({ enabled: true, salt: 'SAPCLOUDSDK4LIFE' });
}, 60000);
}, 10000);

it('should add a disabled analytics file', async () => {
const projectDir = getCleanProjectDir('add-to-gitignore');
fs.copySync(expressAppDir, projectDir, { recursive: true });

await Init.run(['--projectName=testingApp', '--startCommand="npm start"', `--projectDir=${projectDir}`, '--no-analytics']);
await Init.run(['--projectName=testingApp', '--startCommand="npm start"', `--projectDir=${projectDir}`, '--skipInstall', '--no-analytics']);

expect(JSON.parse(fs.readFileSync(`${projectDir}/sap-cloud-sdk-analytics.json`, 'utf8'))).toEqual({ enabled: false });
}, 60000);
}, 10000);
});