Skip to content

Commit

Permalink
refactor: modernize the sample tests (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Dec 19, 2018
1 parent 1d81b61 commit fb71908
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 206 deletions.
8 changes: 3 additions & 5 deletions speech/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "nodejs-docs-samples-speech",
"version": "0.0.1",
"private": true,
"license": "Apache-2.0",
"author": "Google Inc.",
Expand All @@ -9,7 +8,7 @@
"node": ">=8"
},
"scripts": {
"test": "mocha system-test/*.test.js --timeout 600000"
"test": "mocha system-test --timeout 600000"
},
"dependencies": {
"@google-cloud/speech": "^2.1.1",
Expand All @@ -18,10 +17,9 @@
"yargs": "^12.0.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"chai": "^4.2.0",
"execa": "^1.0.0",
"mocha": "^5.2.0",
"proxyquire": "^2.0.1",
"sinon": "^7.0.0",
"uuid": "^3.3.0"
}
}
21 changes: 11 additions & 10 deletions speech/system-test/MicrophoneStream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@

'use strict';

const path = require(`path`);
const assert = require(`assert`);
const path = require('path');
const {assert} = require('chai');
const execa = require('execa');

const {runAsync} = require(`@google-cloud/nodejs-repo-tools`);
const cmd = `node MicrophoneStream.js`;
const cwd = path.join(__dirname, `..`);
const cmd = 'node MicrophoneStream.js';
const cwd = path.join(__dirname, '..');

describe(`MicrophoneStream`, () => {
it(`MicrophoneStream.js Should load and display Yaaaarghs(!) correctly`, async () => {
const output = await runAsync(`${cmd} --help`, cwd);
assert.ok(
output.includes('Streams audio input from microphone, translates to text')
describe('MicrophoneStream', () => {
it('should load and display Yaaaarghs(!) correctly', async () => {
const {stdout} = await execa.shell(`${cmd} --help`, {cwd});
assert.match(
stdout,
/Streams audio input from microphone, translates to text/
);
});
});
152 changes: 61 additions & 91 deletions speech/system-test/betaFeatures.test.js
Original file line number Diff line number Diff line change
@@ -1,124 +1,94 @@
// /**
// * Copyright 2016, 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.
// */

/* eslint-disable */
/**
* Copyright 2016, 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.
*/

'use strict';

const path = require(`path`);
const assert = require(`assert`);

const {runAsync} = require(`@google-cloud/nodejs-repo-tools`);
const path = require('path');
const {assert} = require('chai');
const execa = require('execa');

const cmd = `node betaFeatures.js`;
const cmd = 'node betaFeatures.js';
const cwd = path.join(__dirname, `..`);
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;

//audio file paths
const monoFileName = `commercial_mono.wav`;
const monoFilePath = path.join(__dirname, `../resources/${monoFileName}`);

const stereoFileName = `commercial_stereo.wav`;
const stereoFilePath = path.join(__dirname, `../resources/${stereoFileName}`);
const multiLanguageFileName = `multi.wav`;
const multiLanguageFile = path.join(
__dirname,
`../resources/${multiLanguageFileName}`
);
const resourcePath = path.join(__dirname, '..', 'resources');
const monoFilePath = path.join(resourcePath, 'commercial_mono.wav');
const stereoFilePath = path.join(resourcePath, 'commercial_stereo.wav');
const multiLanguageFile = path.join(resourcePath, 'multi.wav');
const BrooklynFilePath = path.join(resourcePath, 'brooklyn.flac');

const gnomef = `Google_Gnome.wav`;
const gnome = path.join(__dirname, `../resources/${gnomef}`);

const Brooklyn = 'brooklyn.flac';
const BrooklynFilePath = path.join(__dirname, `../resources/${Brooklyn}`);

const monoUri = `gs://cloud-samples-tests/speech/commercial_mono.wav`;
const multiUri = `gs://nodejs-docs-samples/multi_mono.wav`;
const brooklynUri = `gs://cloud-samples-tests/speech/brooklyn.flac`;
const stereoUri = `gs://cloud-samples-tests/speech/commercial_stereo.wav`;
const monoUri = 'gs://cloud-samples-tests/speech/commercial_mono.wav';
const multiUri = 'gs://nodejs-docs-samples/multi_mono.wav';
const brooklynUri = 'gs://cloud-samples-tests/speech/brooklyn.flac';
const stereoUri = 'gs://cloud-samples-tests/speech/commercial_stereo.wav';

describe(`BetaFeatures`, () => {

it(`should run speech diarization on a local file`, async () => {
const output = await runAsync(
`${cmd} Diarization -f ${monoFilePath}`,
cwd
);
assert.ok(
output.includes(`speakerTag: 1`) && output.includes(`speakerTag: 2`)
);
it('should run speech diarization on a local file', async () => {
const output = await exec(`${cmd} Diarization -f ${monoFilePath}`);
assert.match(output, /speakerTag: 1/);
assert.match(output, /speakerTag: 2/);
});

it(`should run speech diarization on a GCS file`, async () => {
const output = await runAsync(`${cmd} DiarizationGCS -u ${monoUri}`, cwd);
assert.ok(
output.includes(`speakerTag: 1`) && output.includes(`speakerTag: 2`)
);
it('should run speech diarization on a GCS file', async () => {
const output = await exec(`${cmd} DiarizationGCS -u ${monoUri}`, cwd);
assert.match(output, /speakerTag: 1/);
assert.match(output, /speakerTag: 2/);
});

it(`should run multi channel transcription on a local file`, async () => {
const output = await runAsync(
`${cmd} multiChannelTranscribe -f ${stereoFilePath}`,
cwd
it('should run multi channel transcription on a local file', async () => {
const output = await exec(
`${cmd} multiChannelTranscribe -f ${stereoFilePath}`
);
assert.ok(output.includes(`Channel Tag: 2`));
assert.match(output, /Channel Tag: 2/);
});

it(`should run multi channel transcription on GCS file`, async () => {
const output = await runAsync(
`${cmd} multiChannelTranscribeGCS -u ${stereoUri}`,
cwd
it('should run multi channel transcription on GCS file', async () => {
const output = await exec(
`${cmd} multiChannelTranscribeGCS -u ${stereoUri}`
);
assert.ok(output.includes(`Channel Tag: 2`));
assert.match(output, /Channel Tag: 2/);
});

it(`should transcribe multi-language on a local file`, async () => {
const output = await runAsync(
`${cmd} multiLanguageTranscribe -f ${multiLanguageFile}`,
cwd
it('should transcribe multi-language on a local file', async () => {
const output = await exec(
`${cmd} multiLanguageTranscribe -f ${multiLanguageFile}`
);
assert.ok(output.includes(`Transcription: how are you doing estoy bien e tu`));
assert.match(output, /Transcription: how are you doing estoy bien e tu/);
});

it(`should transcribe multi-language on a GCS bucket`, async () => {
const output = await runAsync(
`${cmd} multiLanguageTranscribeGCS -u ${multiUri}`,
cwd
);
assert.ok(
output.includes(`Transcription: how are you doing estoy bien e tu`)
it('should transcribe multi-language on a GCS bucket', async () => {
const output = await exec(
`${cmd} multiLanguageTranscribeGCS -u ${multiUri}`
);
assert.match(output, /Transcription: how are you doing estoy bien e tu/);
});

it(`should run word Level Confience on a local file`, async () => {
const output = await runAsync(
it('should run word Level Confience on a local file', async () => {
const output = await exec(
`${cmd} wordLevelConfidence -f ${BrooklynFilePath}`
);
assert.ok(
output.includes(`Transcription: how old is the Brooklyn Bridge`)
);
assert.ok(/Confidence: \d\.\d/.test(output));
assert.match(output, /Transcription: how old is the Brooklyn Bridge/);
assert.match(output, /Confidence: \d\.\d/);
});

it(`should run word level confidence on a GCS bucket`, async () => {
const output = await runAsync(
`${cmd} wordLevelConfidenceGCS -u ${brooklynUri}`,
cwd
);
assert.ok(
output.includes(`Transcription: how old is the Brooklyn Bridge`) &&
/Confidence: \d\.\d/.test(output)
it('should run word level confidence on a GCS bucket', async () => {
const output = await exec(
`${cmd} wordLevelConfidenceGCS -u ${brooklynUri}`
);
assert.match(output, /Transcription: how old is the Brooklyn Bridge/);
assert.match(output, /Confidence: \d\.\d/);
});
});
20 changes: 9 additions & 11 deletions speech/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@

'use strict';

const path = require(`path`);
const assert = require(`assert`);
const path = require('path');
const {assert} = require('chai');
const execa = require('execa');

const cmd = `node quickstart.js`;
const cwd = path.join(__dirname, `..`);
const text = `how old is the Brooklyn Bridge`;
const cwd = path.join(__dirname, '..');
const text = 'how old is the Brooklyn Bridge';

const {runAsync} = require(`@google-cloud/nodejs-repo-tools`);

describe(`Quickstart`, () => {
it(`should run quickstart`, async () => {
const output = await runAsync(`${cmd}`, cwd);
assert.ok(output.includes(`Transcription: ${text}`));
describe('Quickstart', () => {
it('should run quickstart', async () => {
const {stdout} = await execa.shell('node quickstart.js', {cwd});
assert.match(stdout, new RegExp(`Transcription: ${text}`));
});
});
Loading

0 comments on commit fb71908

Please sign in to comment.