Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(headless-chrome):ava to mocha #1159

Merged
Merged
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
5 changes: 3 additions & 2 deletions functions/headless-chrome/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"node": ">=8"
},
"scripts": {
"e2e-test": "export FUNCTIONS_CMD='gcloud beta functions' && sh test/updateFunctions.sh && BASE_URL=\"https://$GCF_REGION-$GCLOUD_PROJECT.cloudfunctions.net/\" ava -T 20s --verbose test/*.test.js"
"e2e-test": "export FUNCTIONS_CMD='gcloud beta functions' && sh test/updateFunctions.sh && BASE_URL=\"https://$GCF_REGION-$GCLOUD_PROJECT.cloudfunctions.net/\" && npm run test",
"test": "mocha test/*.test.js --timeout=60000"
},
"dependencies": {
"puppeteer": "^1.6.2"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "0.25.0",
"mocha": "^5.2.0",
"supertest": "^3.0.0"
},
"cloud-repo-tools": {
Expand Down
28 changes: 13 additions & 15 deletions functions/headless-chrome/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,25 @@
* limitations under the License.
*/

const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const supertest = require(`supertest`);
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');
const supertest = require('supertest');

const BASE_URL = process.env.BASE_URL;

test.before(`Must specify BASE_URL`, t => {
t.truthy(BASE_URL);
before('Must specify BASE_URL', () => {
assert.ok(BASE_URL);
tools.checkCredentials();
});

test.before(tools.checkCredentials);

test.cb(`screenshot: should return a screenshot`, t => {
supertest(BASE_URL)
.get(`/screenshot?url=https://example.com`)
it('screenshot: should return a screenshot', async () => {
await supertest(BASE_URL)
.get('/screenshot?url=https://example.com')
.send()
.expect(200)
.expect(response => {
t.is(response.type, `image/png`);
t.true(response.body instanceof Buffer);
t.true(response.body.length > 0);
})
.end(t.end);
assert.strictEqual(response.type, 'image/png');
assert.strictEqual(response.body instanceof Buffer, true);
assert.strictEqual(response.body.length > 0, true);
});
});