Keen Yee Liau 93078e3709 fix(bazel): Read latest versions from latest-versions.ts & use semver check (#27591)
When @angular/bazel is installed, a postinstall script is run to make sure that
the npm version is *exactly* the same as the Angular repository install by
Bazel. This check is overly stringent. Instead, it should enforce that the
version satisfies the range check instead. This is consistent with the range
defined in angular-cli/packages/schematics/angular/utility/latest-versions.ts.

This commit also fixes the Bazel workspace to use the same Rxjs version if it's
already installed.

PR Close #27591
2018-12-11 16:30:52 -08:00

61 lines
2.2 KiB
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {HostTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
import {clean} from './index';
describe('Bazel-workspace Schematic', () => {
const schematicRunner =
new SchematicTestRunner('@angular/bazel', require.resolve('../collection.json'), );
const defaultOptions = {
name: 'demo',
};
it('should generate Bazel workspace files', () => {
const options = {...defaultOptions};
const host = schematicRunner.runSchematic('bazel-workspace', options);
const files = host.files;
expect(files).toContain('/demo/.bazelignore');
expect(files).toContain('/demo/.bazelrc');
expect(files).toContain('/demo/BUILD.bazel');
expect(files).toContain('/demo/src/BUILD.bazel');
expect(files).toContain('/demo/WORKSPACE');
expect(files).toContain('/demo/yarn.lock');
});
describe('WORKSPACE', () => {
it('should contain project name', () => {
const options = {...defaultOptions};
const host = schematicRunner.runSchematic('bazel-workspace', options);
expect(host.files).toContain('/demo/WORKSPACE');
const content = host.readContent('/demo/WORKSPACE');
expect(content).toContain('workspace(name = "demo")');
});
it('should convert dashes in name to underscore', () => {
const options = {...defaultOptions, name: 'demo-project'};
const host = schematicRunner.runSchematic('bazel-workspace', options);
expect(host.files).toContain('/demo-project/WORKSPACE');
const content = host.readContent('/demo-project/WORKSPACE');
expect(content).toContain('workspace(name = "demo_project"');
});
});
});
describe('clean', () => {
[['1.2.3', '1.2.3'], [' 1.2.3', '1.2.3'], ['1.2.3 ', '1.2.3'], ['~1.2.3', '1.2.3'],
['^1.2.3', '1.2.3'], ['v1.2.3', '1.2.3'], ['1.2', null], ['a.b.c', null],
].forEach(([version, want]: [string, string]) => {
it(`should match ${version} with ${want}`, () => {
const got = clean(version);
expect(got).toBe(want);
});
});
});