diff --git a/.kokoro/build-xunit.sh b/.kokoro/build-xunit.sh new file mode 100755 index 0000000000..a0a3615f7f --- /dev/null +++ b/.kokoro/build-xunit.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Copyright 2019 Google LLC. +# +# Licensed 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. + +BUILD_SH=$(pwd)/$(dirname $0)/build.sh + +# Setup +cd github/nodejs-docs-samples/${PROJECT} +export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/secrets-key.json +gcloud auth activate-service-account --key-file "$GOOGLE_APPLICATION_CREDENTIALS" +gcloud config set project $GCLOUD_PROJECT + +if [ ! -f './.mocharc.yml' ] +then + +# Note: since this a "heredoc", it must be un-indented +cat << REPORTER > .mocharc.yml +reporter: xunit +reporter-option: + - output=./test.xml +REPORTER +fi + +# Run build script + capture exit code +sh $BUILD_SH +CODE=$? + +# Store XUnit configs +export XUNIT_BUCKET="nodejs-docs-samples-kokoro-test" +gsutil cp ./test.xml gs://${XUNIT_BUCKET}/test_${KOKORO_BUILD_ID}.xml + +# Return captured code +exit $CODE \ No newline at end of file diff --git a/.kokoro/functions/background.cfg b/.kokoro/functions/background.cfg index fa0b71aa1f..5513f5e879 100644 --- a/.kokoro/functions/background.cfg +++ b/.kokoro/functions/background.cfg @@ -9,5 +9,5 @@ env_vars: { # Tell the trampoline which build file to use. env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/nodejs-docs-samples/.kokoro/build.sh" + value: "github/nodejs-docs-samples/.kokoro/build-xunit.sh" } diff --git a/functions/background/test/index.test.js b/functions/background/test/index.test.js index 4f08788cad..c9727a6e52 100644 --- a/functions/background/test/index.test.js +++ b/functions/background/test/index.test.js @@ -36,70 +36,76 @@ function getSample() { beforeEach(tools.stubConsole); afterEach(tools.restoreConsole); -it('should echo message', () => { - const event = { - data: { - myMessage: 'hi', - }, - }; - const sample = getSample(); - const callback = sinon.stub(); - - sample.program.helloWorld(event, callback); +describe('functions_background_helloworld', () => { + it('should echo message', () => { + const event = { + data: { + myMessage: 'hi', + }, + }; + const sample = getSample(); + const callback = sinon.stub(); - assert.strictEqual(console.log.callCount, 1); - assert.deepStrictEqual(console.log.firstCall.args, [event.data.myMessage]); - assert.strictEqual(callback.callCount, 1); - assert.deepStrictEqual(callback.firstCall.args, []); -}); + sample.program.helloWorld(event, callback); -it('should say no message was provided', () => { - const error = new Error('No message defined!'); - const callback = sinon.stub(); - const sample = getSample(); - sample.program.helloWorld({data: {}}, callback); + assert.strictEqual(console.log.callCount, 1); + assert.deepStrictEqual(console.log.firstCall.args, [event.data.myMessage]); + assert.strictEqual(callback.callCount, 1); + assert.deepStrictEqual(callback.firstCall.args, []); + }); - assert.strictEqual(callback.callCount, 1); - assert.deepStrictEqual(callback.firstCall.args, [error]); -}); + it('should say no message was provided', () => { + const error = new Error('No message defined!'); + const callback = sinon.stub(); + const sample = getSample(); + sample.program.helloWorld({data: {}}, callback); -it('should make a promise request', () => { - const sample = getSample(); - const event = { - data: { - endpoint: 'foo.com', - }, - }; - - return sample.program.helloPromise(event).then(result => { - assert.deepStrictEqual(sample.mocks.requestPromiseNative.firstCall.args, [ - {uri: 'foo.com'}, - ]); - assert.strictEqual(result, 'test'); + assert.strictEqual(callback.callCount, 1); + assert.deepStrictEqual(callback.firstCall.args, [error]); }); }); -it('should return synchronously', () => { - assert.strictEqual( - getSample().program.helloSynchronous({ +describe('functions_background_promise', () => { + it('should make a promise request', () => { + const sample = getSample(); + const event = { data: { - something: true, + endpoint: 'foo.com', }, - }), - 'Something is true!' - ); + }; + + return sample.program.helloPromise(event).then(result => { + assert.deepStrictEqual(sample.mocks.requestPromiseNative.firstCall.args, [ + {uri: 'foo.com'}, + ]); + assert.strictEqual(result, 'test'); + }); + }); }); -it('should throw an error', () => { - assert.throws( - () => { +describe('functions_background_synchronous', () => { + it('should return synchronously', () => { + assert.strictEqual( getSample().program.helloSynchronous({ data: { - something: false, + something: true, }, - }); - }, - Error, - 'Something was not true!' - ); + }), + 'Something is true!' + ); + }); + + it('should throw an error', () => { + assert.throws( + () => { + getSample().program.helloSynchronous({ + data: { + something: false, + }, + }); + }, + Error, + 'Something was not true!' + ); + }); });