Skip to content

Commit

Permalink
Merge pull request #32 from percy/david_jones/ch199/add-user-agents-t…
Browse files Browse the repository at this point in the history
…o-all-clients

Add user agent support
  • Loading branch information
djones authored Jun 30, 2017
2 parents fe416f2 + 096ac9b commit fe47503
Show file tree
Hide file tree
Showing 5 changed files with 939 additions and 1,202 deletions.
2 changes: 0 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"name": "ember-percy",
"dependencies": {
"ember": "~2.9.0",
"ember-cli-shims": "0.1.3"
}
}
54 changes: 52 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var Environment = require('percy-client/dist/environment');
var PromisePool = require('es6-promise-pool');
var walk = require('walk');


// Some build assets we never want to upload.
var SKIPPED_ASSETS = [
'/assets/tests.js',
Expand Down Expand Up @@ -115,12 +114,49 @@ var isPercyEnabled = true;
module.exports = {
name: 'ember-percy',

_clientInfo: function() {
if(!this._clientInfoCache) {
var version = require('./package.json').version;
this._clientInfoCache = `${this.name}/${version}`;
}

return this._clientInfoCache;
},

_environmentInfo: function() {
if(!this._environmentInfoCache) {
this._environmentInfoCache = [
`ember/${this._emberSourceVersion()}`,
`ember-cli/${this._emberCliVersion()}`
].join('; ');
}

return this._environmentInfoCache;
},

_emberSourceVersion: function() {
try {
return require('ember-source/package.json').version;
} catch (e) {
return 'unknown';
};
},

_emberCliVersion: function() {
try {
return require('ember-cli/lib/utilities/version-utils').emberCLIVersion();
} catch (e) {
return 'unknown';
};
},

// Only allow the addon to be incorporated in non-production envs.
isEnabled: function() {
// This cannot be just 'test', because people often run tests from development servers, and the
// helper imports will fail since ember-cli excludes addon files entirely if not enabled.
return (process.env.EMBER_ENV !== 'production');
},

// Grab and store the `percy` config set in an app's config/environment.js.
config: function(env, baseConfig) {
percyConfig = baseConfig.percy || {};
Expand All @@ -131,6 +167,7 @@ module.exports = {
// Make sure the percy config has a 'breakpoints' object.
percyConfig.breakpointsConfig = percyConfig.breakpointsConfig || {};
},

// Inject percy finalization into the footer of tests/index.html.
contentFor: function(type) {
// Disable finalize injection if Percy is explicitly disabled or if not in an 'ember test' run.
Expand All @@ -147,6 +184,7 @@ module.exports = {
";
}
},

// After build output is ready, create a Percy build and upload missing build resources.
outputReady: function(result) {
var token = process.env.PERCY_TOKEN;
Expand All @@ -160,7 +198,12 @@ module.exports = {
}

if (token && repo && isPercyEnabled) {
percyClient = new PercyClient({token: token, apiUrl: apiUrl});
percyClient = new PercyClient({
token: token,
apiUrl: apiUrl,
clientInfo: this._clientInfo(),
environmentInfo: this._environmentInfo(),
});
} else {
isPercyEnabled = false;

Expand All @@ -173,6 +216,7 @@ module.exports = {
'[percy][WARNING] Percy is disabled, no PERCY_PROJECT environment variable found.')
}
}

if (!isPercyEnabled) { return; }

var hashToResource = gatherBuildResources(percyClient, result.directory);
Expand Down Expand Up @@ -212,6 +256,7 @@ module.exports = {
console.log('\n[percy] Uploaded new build resource: ' + resource.resourceUrl);
}, handlePercyFailure);
buildResourceUploadPromises.push(promise);

return promise;
} else {
// Trigger the pool to end.
Expand All @@ -235,6 +280,7 @@ module.exports = {
resolve();
}
},

function(error) {
handlePercyFailure(error);

Expand All @@ -244,6 +290,7 @@ module.exports = {
);
});
},

testemMiddleware: function(app) {
// Add middleware to add request.body because it is not populated in express by default.
app.use(bodyParser.json({limit: '50mb'}));
Expand All @@ -269,6 +316,7 @@ module.exports = {
for (var i in snapshotBreakpoints) {
var breakpointName = snapshotBreakpoints[i];
var breakpointWidth = percyConfig.breakpointsConfig[breakpointName];

if (!parseInt(breakpointWidth)) {
response.status(400);
response.send(
Expand Down Expand Up @@ -372,10 +420,12 @@ module.exports = {
response.contentType('application/json');
response.send(JSON.stringify({success: success}));
}

function handleError(error) {
handlePercyFailure(error);
sendResponse(false);
}

if (!isPercyEnabled) {
sendResponse(true);
return;
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^2.4.1",
"ember-cli": "2.9.1",
"ember-cli": "2.13.3",
"ember-cli-app-version": "^2.0.0",
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-htmlbars": "^1.0.10",
"ember-cli-htmlbars-inline-precompile": "^0.3.3",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-jshint": "^1.0.4",
"ember-cli-shims": "^1.1.0",
"ember-cli-qunit": "^3.0.1",
"ember-cli-release": "^0.2.9",
"ember-cli-test-loader": "^1.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.9.0",
"ember-data": "^2.13.0",
"ember-source": "~2.13.0",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-export-application-global": "^1.0.5",
"ember-load-initializers": "^0.5.1",
Expand All @@ -48,7 +50,7 @@
"body-parser": "^1.15.0",
"ember-cli-babel": "^5.1.7",
"es6-promise-pool": "^2.4.1",
"percy-client": "^2.0.0",
"percy-client": "^2.1.3",
"walk": "^2.3.9"
},
"ember-addon": {
Expand Down
2 changes: 0 additions & 2 deletions tests/dummy/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import config from './config/environment';

let App;

Ember.MODEL_FACTORY_INJECTIONS = true;

App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Expand Down
Loading

0 comments on commit fe47503

Please sign in to comment.