Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .kokoro/build-xunit.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .kokoro/functions/background.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
110 changes: 58 additions & 52 deletions functions/background/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!'
);
});
});