cordova-android/spec/unit/builders/builders.spec.js
Raphael von der Grün 1f0ea173b0
refactor: do not infer project root from script location (#1265)
* fix(Api): do not infer project root from script location

* fix(builders): do not infer project root from script location

* fix(target): do not infer project root from script location

* test(e2e): cleanup and extend E2E tests

- Renames the file with the only existing E2E test
- Makes existing test use the API instance returned by
  `Api.createPlatform`
- Adds another test that ensures we can still require the API from
  `platformProjectPath/cordova/Api.js`

* fix(check_reqs): do not infer project root from script location
2021-07-13 08:51:20 +02:00

48 lines
1.8 KiB
JavaScript

/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const rewire = require('rewire');
const CordovaError = require('cordova-common').CordovaError;
const ProjectBuilder = require('../../../bin/templates/cordova/lib/builders/ProjectBuilder');
describe('builders', () => {
let builders;
beforeEach(() => {
builders = rewire('../../../bin/templates/cordova/lib/builders/builders');
});
describe('getBuilder', () => {
it('should return an instance of ProjectBuilder when gradle is requested', () => {
const root = 'FakeProjectRoot';
const newBuilder = builders.getBuilder(root);
expect(newBuilder).toEqual(jasmine.any(ProjectBuilder));
expect(newBuilder.root).toBe(root);
});
it('should throw an error if a builder cannot be instantiated', () => {
const requireSpy = jasmine.createSpy('require').and.throwError();
builders.__set__('require', requireSpy);
expect(() => builders.getBuilder()).toThrow(jasmine.any(CordovaError));
});
});
});