Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to test analytics code
Browse files Browse the repository at this point in the history
kneth committed Jan 27, 2022
1 parent 3ef00cb commit d41cd23
Showing 4 changed files with 41 additions and 3 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/pr-analytics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Analytics (Pull Request)
on: pull_request
env:
REALM_DISABLE_ANALYTICS: 1
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
- uses: actions/setup-node@v1
with:
node-version: 14
registry-url: https://registry.npmjs.org/
- name: Install npm v7
run: npm install -g npm@7
# Install the root package (--ignore-scripts to avoid downloading or building the native module)
- name: Install root package dependencies
run: npm ci --ignore-scripts
- name: Install subpackages dependencies
run: npm run lerna:bootstrap
-name: Run postinstall script
run: npx lerna run test:analytics
3 changes: 2 additions & 1 deletion integration-tests/tests/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,8 @@
"test:performance": "CONTEXT=missingServer,performance,integration=false,$CONTEXT npm test",
"app-importer": "realm-app-importer serve ../realm-apps",
"mocha": "mocha src/index.ts",
"lint": "eslint --ext .js,.ts ."
"lint": "eslint --ext .js,.ts .",
"test:analytics": "node ../../scripts/submit-analytics --test | grep ^payload | cut -f2- -d' ' | jq '.webHook.properties' | jq 'keys' | jq 'join(\",\")' | grep -c 'Anonymized Application ID,Anonymized Machine Identifier,Binding,Framework,Framework Version,Host OS Type,Host OS Version,JS Analytics Version,JavaScript Engine,Language,Node.js version,Version,distinct_id,token'"
},
"peerDependencies": {
"bson": "^4.2.3",
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -75,7 +75,8 @@
"check-environment": "node scripts/check-environment.js",
"lint:cpp": "find src -name \"*.?pp\" | xargs clang-format --dry-run --Werror",
"lint:fix:cpp": "find src -name \"*.?pp\" | xargs clang-format -i",
"postinstall": "node scripts/submit-analytics.js"
"postinstall": "node scripts/submit-analytics.js",
"test:postinstall": "lerna run test:analytics"
},
"dependencies": {
"@realm.io/common": "^0.1.1",
13 changes: 12 additions & 1 deletion scripts/submit-analytics.js
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ async function submitAnalytics(dryRun) {

const wd = process.cwd();
const index = wd.indexOf("node_modules");
const packageJson = wd.slice(0, index) + "/package.json";
const packageJson = (index === -1 ? wd : wd.slice(0, index)) + "/package.json";
const context = require(packageJson);
const payload = await fetchPlatformData(context);
doLog(`payload: ${JSON.stringify(payload)}`);
@@ -174,6 +174,7 @@ async function submitAnalytics(dryRun) {
const optionDefinitions = [
{ name: "dryRun", type: Boolean, multiple: false, description: "If true, don't submit analytics" },
{ name: "log", type: Boolean, multiple: false, description: "If true, print log messages" },
{ name: "test", type: Boolean, multiple: false, description: "If true, run as --dryRun --log" },
];

const options = commandLineArgs(optionDefinitions, { camelCase: true });
@@ -183,7 +184,17 @@ if (options.dryRun) {
dryRun = true;
}

let log = false;
if (options.log) {
log = true;
}

if (options.test) {
dryRun = true;
log = true;
}

if (log) {
doLog = (msg) => console.log(msg);
} else {
// eslint-disable-next-line no-unused-vars

0 comments on commit d41cd23

Please sign in to comment.