Skip to content

Commit

Permalink
Switch from Mocha to Ava for faster tests (#289)
Browse files Browse the repository at this point in the history
* Switch from Mocha to Ava

* Concurrency: 5
  • Loading branch information
jmdobry authored and Ace Nassri committed Nov 17, 2022
1 parent 97f7d1c commit a355973
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 42 deletions.
4 changes: 2 additions & 2 deletions speech/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"dependencies": {
"@google-cloud/speech": "0.5.0",
"node-record-lpcm16": "0.1.4",
"yargs": "6.5.0"
"node-record-lpcm16": "0.2.0",
"yargs": "6.6.0"
},
"engines": {
"node": ">=4.3.2"
Expand Down
64 changes: 35 additions & 29 deletions speech/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

'use strict';

require(`../../system-test/_setup`);

const path = require(`path`);
const proxyquire = require(`proxyquire`).noPreserveCache();
const speech = proxyquire(`@google-cloud/speech`, {})();
Expand All @@ -25,34 +27,38 @@ const config = {
sampleRate: 16000
};

describe(`speech:quickstart`, () => {
it(`should detect speech`, (done) => {
const expectedFileName = `./resources/audio.raw`;
const expectedText = `how old is the Brooklyn Bridge`;

const speechMock = {
recognize: (_fileName, _config) => {
assert.equal(_fileName, expectedFileName);
assert.deepEqual(_config, config);

return speech.recognize(fileName, config)
.then((results) => {
const transcription = results[0];
assert.equal(transcription, expectedText);

setTimeout(() => {
assert.equal(console.log.callCount, 1);
assert.deepEqual(console.log.getCall(0).args, [`Transcription: ${expectedText}`]);
done();
}, 200);

return results;
});
}
};

proxyquire(`../quickstart`, {
'@google-cloud/speech': sinon.stub().returns(speechMock)
});
test.before(stubConsole);
test.after(restoreConsole);

test.cb(`should detect speech`, (t) => {
const expectedFileName = `./resources/audio.raw`;
const expectedText = `how old is the Brooklyn Bridge`;

const speechMock = {
recognize: (_fileName, _config) => {
t.is(_fileName, expectedFileName);
t.deepEqual(_config, config);

return speech.recognize(fileName, config)
.then(([transcription]) => {
t.is(transcription, expectedText);

setTimeout(() => {
try {
t.is(console.log.callCount, 1);
t.deepEqual(console.log.getCall(0).args, [`Transcription: ${expectedText}`]);
t.end();
} catch (err) {
t.end(err);
}
}, 200);

return [transcription];
});
}
};

proxyquire(`../quickstart`, {
'@google-cloud/speech': sinon.stub().returns(speechMock)
});
});
24 changes: 13 additions & 11 deletions speech/system-test/recognize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,26 @@

'use strict';

require(`../../system-test/_setup`);

const path = require(`path`);
const run = require(`../../utils`).run;

const cmd = `node recognize.js`;
const cwd = path.join(__dirname, `..`);
const filename = `./resources/audio.raw`;
const text = `how old is the Brooklyn Bridge`;

describe(`speech:recognize`, () => {
it(`should run sync recognize`, () => {
assert.equal(run(`${cmd} sync ${filename}`, cwd).includes(text), true);
});
test(`should run sync recognize`, async (t) => {
const output = await runAsync(`${cmd} sync ${filename}`, cwd);
t.true(output.includes(`Transcription: ${text}`));
});

it(`should run async recognize`, () => {
assert.equal(run(`${cmd} async ${filename}`, cwd).includes(text), true);
});
test(`should run async recognize`, async (t) => {
const output = await runAsync(`${cmd} async ${filename}`, cwd);
t.true(output.includes(`Transcription: ${text}`));
});

it(`should run streaming recognize`, () => {
assert.equal(run(`${cmd} stream ${filename}`, cwd).includes(text), true);
});
test(`should run streaming recognize`, async (t) => {
const output = await runAsync(`${cmd} stream ${filename}`, cwd);
t.true(output.includes(text));
});

0 comments on commit a355973

Please sign in to comment.