Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
Merge ce4581d into 8be6783
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Nov 29, 2018
2 parents 8be6783 + ce4581d commit 883fd33
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
103 changes: 103 additions & 0 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,109 @@ describe('generator-console-package:app:@easyops', () => {
});
});

describe('generator-console-package:app:@brick', () => {
const random = Math.random().toString(36).substring(7);
const Random = random.substr(0, 1).toUpperCase() + random.substr(1);
const packageName = `just-for-test-2-${random}`;
const pascalCaseName = `JustForTest2${Random}`;
let mockSpawn;

beforeAll(() => {

return helpers
.run(path.join(__dirname, '../generators/app'))
.inTmpDir(dir => {
fs.copySync(path.join(__dirname, '../generators/app/templates/library/mock'), dir);
fs.writeJsonSync(path.resolve(dir, './package.json'), { name: 'unknown' });
})
.on('ready', gen => {
mockSpawn = sandbox.stub(gen, 'spawnCommand').callsFake(() => {
const spawnEvent = new EventEmitter();
process.nextTick(() => {
spawnEvent.emit('close');
});
return spawnEvent;
});
})
.withPrompts({
scope: '@brick',
packageName
});
});

afterAll(() => {
sandbox.restore();
});

it('should create files', () => {
assert.file([
// Created files:
`@brick/${packageName}/src/components/${packageName}.component.html`,
`@brick/${packageName}/src/components/${packageName}.component.scss`,
`@brick/${packageName}/src/components/${packageName}.component.spec.ts`,
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`@brick/${packageName}/src/index.module.ts`,
`@brick/${packageName}/package.json`,
`@brick/${packageName}/public_api.ts`,
`@brick/${packageName}/README.md`,

// Modified files:
'angular.json',
'tsconfig.json'
]);
});

it('should create correct files', () => {
assert.fileContent(
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`selector: "${packageName}"`
);
assert.fileContent(
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`templateUrl: "./${packageName}.component.html"`
);
assert.fileContent(
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`styleUrls: ["./${packageName}.component.scss"]`
);
assert.fileContent(
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`styleUrls: ["./${packageName}.component.scss"]`
);
assert.fileContent(
`@brick/${packageName}/src/components/${packageName}.component.ts`,
`export class ${pascalCaseName}Component implements OnInit`
);
assert.fileContent(
`@brick/${packageName}/src/index.module.ts`,
`export class ${pascalCaseName}Module`
);
assert.fileContent(
`@brick/${packageName}/package.json`,
`"name": "@brick/${packageName}"`
);
});

it('should update files', () => {
assert.fileContent(
'angular.json',
`"${packageName}": {\n "root": "@brick/${packageName}/src"`
);
assert.fileContent(
'tsconfig.json',
`"@brick/${packageName}": [\n "@brick/${packageName}"\n ]`
);
});

it('should run `yarn link`', () => {
expect(mockSpawn.calledOnceWithExactly('yarn', ['link'], {
cwd: `@brick/${packageName}/dist`
})).toBe(true);

expect(mockSpawn.callCount).toBe(1);
});
});

describe('generator-console-package:app:@plugin-common', () => {
const random = Math.random().toString(36).substring(7);
const Random = random.substr(0, 1).toUpperCase() + random.substr(1);
Expand Down
4 changes: 4 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ scopePropsMap.set('@easyops', {
repository: 'Console-W',
subPackagePath: 'packages'
});
scopePropsMap.set('@brick', {
repository: 'console-plugins',
subPackagePath: '@brick'
});
scopePropsMap.set('@plugin-common', {
repository: 'console-plugins',
subPackagePath: '@plugin-common'
Expand Down

0 comments on commit 883fd33

Please sign in to comment.