Skip to content

Commit

Permalink
update test script
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseykulikov committed Oct 14, 2023
1 parent 0f8117e commit 318c147
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
19 changes: 19 additions & 0 deletions script/crux-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// usage:
// • CRUX_KEY='...' node script/crux-api.js record '{"origin": "https://example.com", "formFactor": "DESKTOP", "effectiveConnectionType": "4G" }' > results/record-example.json
// • CRUX_KEY='...' node script/crux-api.js history '{"url": "https://www.apple.com/", "formFactor": "PHONE" }' > results/history-apple.json

import nodeFetch from 'node-fetch'
import { createQueryRecord, createQueryHistoryRecord } from '../src/index.js'

const key = process.env.CRUX_KEY || 'no-key'
const apiMethod = process.argv[2] || 'record'
const params = JSON.parse(process.argv[3] || '')

try {
const createMethod = apiMethod === 'record' ? createQueryRecord : createQueryHistoryRecord
const queryMethod = createMethod({ key, fetch: nodeFetch })
const res = await queryMethod(params)
console.log(JSON.stringify(res, null, ' '))
} catch (err) {
console.error(err)
}
15 changes: 0 additions & 15 deletions script/queryRecord.js

This file was deleted.

0 comments on commit 318c147

Please sign in to comment.