Skip to content

Commit

Permalink
test: Added deeper testing for gradle argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
breautek committed Apr 22, 2023
1 parent facf72f commit 1421eff
Showing 1 changed file with 116 additions and 0 deletions.
116 changes: 116 additions & 0 deletions spec/unit/build.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
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 builders = require('../../lib/builders/builders');

describe('build', () => {
let build;
const builder = builders.getBuilder('FakeRootPath');

beforeEach(() => {
build = rewire('../../lib/build');
build.__set__({
events: jasmine.createSpyObj('eventsSpy', ['emit'])
});

// run needs `this` to behave like an Api instance
build.run = build.run.bind({
_builder: builder
});

spyOn(builder, 'build').and.returnValue(Promise.resolve({
paths: ['fake.apk'],
buildtype: 'debug'
}));
});

describe('argument parsing', () => {
let prepEnvSpy;

beforeEach(() => {
prepEnvSpy = spyOn(builder, 'prepEnv').and.returnValue(Promise.resolve());
});

describe('gradleArg', () => {
const baseOptions = {
packageType: 'apk',
arch: undefined,
prepEnv: undefined,
buildType: 'debug'
};

it('can parse single gradle argument', async () => {
await build.run({
argv: [
'node',
'--gradleArg=--stacktrace'
]
});

expect(prepEnvSpy).toHaveBeenCalledWith({
...baseOptions,
extraArgs: ['--stacktrace']
});
});

it('can parse multiple gradle arguments', async () => {
await build.run({
argv: [
'node',
'--gradleArg=--stacktrace --info'
]
});

expect(prepEnvSpy).toHaveBeenCalledWith({
...baseOptions,
extraArgs: ['--stacktrace', '--info']
});
});

it('can parse multiple gradle arguments with strings', async () => {
await build.run({
argv: [
'node',
'--gradleArg=--testArg="hello world"'
]
});

expect(prepEnvSpy).toHaveBeenCalledWith({
...baseOptions,
extraArgs: ['--testArg="hello world"']
});
});

it('gradle args will split when necessary', async () => {
await build.run({
argv: [
'node',
'--gradleArg=--warning-mode all'
]
});

expect(prepEnvSpy).toHaveBeenCalledWith({
...baseOptions,
extraArgs: ['--warning-mode', 'all']
});
});
});
});
});

0 comments on commit 1421eff

Please sign in to comment.