Skip to content

Commit

Permalink
Improve test vendor requests macros (#26828)
Browse files Browse the repository at this point in the history
  • Loading branch information
Micajuine Ho committed Feb 21, 2020
1 parent 50717b0 commit ddfd41b
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 183 deletions.
27 changes: 16 additions & 11 deletions extensions/amp-analytics/0.1/test/test-vendors-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ describes.realWin(
.stub(urlReplacements.getVariableSource(), 'get')
.callsFake(function(name) {
expect(this.replacements_).to.have.property(name);
const defaultValue = `_${name.toLowerCase()}_`;
return {
sync: () => defaultValue,
sync: (...args) => mockMacrosBinding(name, args),
};
});

Expand Down Expand Up @@ -123,15 +122,7 @@ describes.realWin(
const keys = Object.keys(merged);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
merged[key] = (...args) => {
let params = args
.filter(val => val !== undefined)
.join(',');
if (params) {
params = '(' + params + ')';
}
return `_${key.replace('$', '').toLowerCase()}${params}_`;
};
merged[key] = (...args) => mockMacrosBinding(key, args);
}
return /** @type {!JsonObject} */ (merged);
});
Expand Down Expand Up @@ -246,3 +237,17 @@ function writeOutput(vendor, output) {
out.textContent = JSON.stringify(output, null, ' ');
top.document.body.insertBefore(out, firstChild);
}

/**
* CLIENT_ID(_ga) -> _client_id(_ga)_
* $NOT(true) -> _not(true)_
* @param {string} macroName
* @param {!Array<string>} argumentsList
*/
function mockMacrosBinding(macroName, argumentsList) {
let params = argumentsList.filter(val => val !== undefined).join(',');
if (params) {
params = '(' + params + ')';
}
return `_${macroName.replace('$', '').toLowerCase()}${params}_`;
}

0 comments on commit ddfd41b

Please sign in to comment.