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

Remove jQuery #45

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0eec008
use ajax from ember-fetch
jeffjewiss Sep 26, 2017
43ee94e
remove jquery usage from snapshot
jeffjewiss Oct 7, 2017
7bdc03f
upgrade from jshint to eslint
jeffjewiss Oct 7, 2017
a951f0a
make eslint config easier to read
jeffjewiss Oct 7, 2017
39f9297
setup eslint with ember rules to warn for jquery
jeffjewiss Oct 7, 2017
5d54538
install dependencies for running tests without jquery
jeffjewiss Oct 7, 2017
010a7d7
upgrade ember-cli-babel and peer deps
jeffjewiss Oct 7, 2017
adcd1ff
use babel polyfill in testing
jeffjewiss Oct 7, 2017
5f241e1
use native dom helpers in tests
jeffjewiss Oct 7, 2017
b35c6fe
remove remaining references to jshint
jeffjewiss Oct 7, 2017
866f396
Finish removing jquery in the addon
jeffjewiss Oct 7, 2017
f848919
add use strict for node 4
jeffjewiss Oct 7, 2017
b951438
install bower globally on appveyor
jeffjewiss Oct 7, 2017
ee24ec4
update travis config with latest
jeffjewiss Oct 7, 2017
4425ec7
try switching quotes for build script
jeffjewiss Oct 7, 2017
46770e4
try not caching yarn with travis
jeffjewiss Oct 7, 2017
3bcbcef
use node 6/8 on travis, update engines
jeffjewiss Oct 7, 2017
9dc3f5b
test ember 2.8, 2.12, not 1.13, 2.4
jeffjewiss Oct 7, 2017
ab67d27
fix ember try config and update ember cli
jeffjewiss Oct 8, 2017
cec400f
add ember try files to gitignore
jeffjewiss Oct 9, 2017
3a16b39
Have Travis and Appveyor test Node 4
jeffjewiss Oct 13, 2017
f1b813e
Test Ember 1.13 with ember-try
jeffjewiss Oct 13, 2017
ca05a92
Clean up travis config
jeffjewiss Oct 17, 2017
cbedc0f
Add headless chrome config to testem
jeffjewiss Oct 17, 2017
e1bfed2
Fix usage of snapshot async helper
jeffjewiss Oct 17, 2017
f0d276d
Fix ajax call and remove jQuery mocks
jeffjewiss Oct 17, 2017
0f64872
Merge branch 'master' into remove-jquery
jeffjewiss Oct 29, 2017
4904f93
Update textarea text/values after dom copy
jeffjewiss Oct 29, 2017
7a38190
Merge branch 'master' into remove-jquery
jeffjewiss Nov 15, 2017
a4d4345
Merge branch 'master' into remove-jquery
jeffjewiss Jan 9, 2018
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
44 changes: 44 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
},
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
env: {
browser: true
},
globals: {
'percySnapshot': true,
'Promise': true
},
rules: {
'no-cond-assign': [
'error',
'except-parens'
],
'curly': 'error',
'no-debugger': 'off',
'eqeqeq': 'error',
'no-eval': 'error',
'guard-for-in': 'off',
'wrap-iife': 'off',
'linebreak-style': 'off',
'new-cap': 'error',
'no-caller': 'error',
'no-empty': 'off',
'no-new': 'off',
'no-plusplus': 'off',
'no-undef': 'error',
'dot-notation': 'off',
'strict': 'off',
'no-eq-null': 'error',
'no-unused-vars': 'error',
'ember/no-global-jquery': 'warn',
'ember/no-jquery': 'warn',
'ember/named-functions-in-promises': 'off'
}
};
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@
/libpeerconnection.log
npm-debug.log*
testem.log
yarn-error.log
testem.log

# ember-try
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
32 changes: 0 additions & 32 deletions .jshintrc

This file was deleted.

33 changes: 20 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
---
sudo: false
dist: trusty

addons:
chrome: stable

language: node_js
node_js:
- "4"

sudo: false
- "6"
- "8"

cache:
yarn: true
directories:
- node_modules
- $HOME/.npm
- $HOME/.cache

env:
# we recommend testing LTS's and latest stable release (bonus points to beta/canary)
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-1.13
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-lts-2.4
- EMBER_TRY_SCENARIO=ember-release
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-beta
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-canary
global:
- JOBS=1
matrix:
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-1.13
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-lts-2.8
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-lts-2.12
- EMBER_TRY_SCENARIO=ember-release
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-beta
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-canary

matrix:
fast_finish: true
Expand All @@ -27,14 +36,12 @@ matrix:
before_install:
- yarn global add bower
- bower --version
- yarn add phantomjs-prebuilt
- node_modules/phantomjs-prebuilt/bin/phantomjs --version

install:
- yarn
- bower install

script:
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
# to the addon's original dependency state, skipping "cleanup".
- ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup
38 changes: 18 additions & 20 deletions addon/finalize.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import Ember from 'ember';
import { getNativeXhr } from './native-xhr';
import { maybeDisableMockjax, maybeResetMockjax } from './mockjax-wrapper';
import ajax from 'ember-fetch/ajax';

// See: https://github.com/github/fetch/issues/175#issuecomment-125779262
function responseTimeout(ms, promise) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
reject(new Error("Response timeout"))
}, ms)
promise.then(resolve, reject)
})
}

// Percy finalizer to be called at the very end of the test suite.
// Note: it is important that this is called always, no matter if percySnapshot was used or not,
// to support parallelized test runners with Percy's aggregation of parallel finalize calls.
function finalizeBuildOnce(config, data, callback) {
maybeDisableMockjax();
let options = {
xhr: getNativeXhr,
method: 'POST',
// Use "async: false" to block the browser from shutting down until the finalize_build call
// has fully returned. This prevents testem from shutting down the express server until
// our middleware has finished uploading resources and resolving promises.
async: false,
timeout: 30000,
};
Ember.$.ajax('/_percy/finalize_build', options)
.done( () => {
if(callback) {
callback();
}
});
maybeResetMockjax();
return responseTimeout(30000, ajax('/_percy/finalize_build', {
method: 'POST'
})).then(function() {
if (callback) {
return callback();
}
})
}

// When imported into test-body-footer, register Testem hook to know when all tests are finished.
Expand Down
16 changes: 0 additions & 16 deletions addon/mockjax-wrapper.js

This file was deleted.

9 changes: 0 additions & 9 deletions addon/native-xhr.js

This file was deleted.

97 changes: 56 additions & 41 deletions addon/snapshot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import Ember from 'ember';
import { getNativeXhr } from './native-xhr';
import { maybeDisableMockjax, maybeResetMockjax } from './mockjax-wrapper';
import ajax from 'ember-fetch/ajax';
import run from 'ember-runloop';

function matches(el, selector) {
return (
el.matches ||
el.matchesSelector ||
el.msMatchesSelector ||
el.mozMatchesSelector ||
el.webkitMatchesSelector ||
el.oMatchesSelector
).call(el, selector);
}

function getDoctype() {
let doctypeNode = document.doctype;
Expand All @@ -16,38 +26,44 @@ function getDoctype() {
return doctype;
}

function bubbleErrors(response) {
if (response.status === 400) {
// Bubble up 400 errors, ie. when given options are invalid.
let error = new Error(response.statusText);
error.response = response;
throw error;
}
}

// Set the property value into the attribute value for snapshotting inputs
function setAttributeValues(dom) {
// List of input types here https://www.w3.org/TR/html5/forms.html#the-input-element

// Limit scope to inputs only as textareas do not retain their value when cloned
let elems = dom.find(
`input[type=text], input[type=search], input[type=tel], input[type=url], input[type=email],
let elems = dom.querySelectorAll(
`input[type=text], input[type=search], input[type=tel], input[type=url], input[type=email],
input[type=password], input[type=number], input[type=checkbox], input[type=radio]`
);

Ember.$(elems).each(function() {
let elem = Ember.$(this);
switch(elem.attr('type')) {
Array.prototype.forEach.call(elems, function(elem) {
switch(elem.getAttribute('type')) {
case 'checkbox':
case 'radio':
if (elem.is(':checked')) {
elem.attr('checked', '');
if (matches(elem, ':checked')) {
elem.setAttribute('checked', '');
}
break;
default:
elem.attr('value', elem.val());
elem.setAttribute('value', elem.value);
}
});

return dom;
}

// jQuery clone() does not copy textarea contents, so we explicitly do it here.
function setTextareaContent(dom) {
dom.find('textarea').each(function() {
let elem = Ember.$(this);
elem.text(elem.val());
Array.prototype.forEach.call(dom.querySelectorAll('textarea'), function(elem) {
elem.textContent = elem.value;
});

return dom;
Expand All @@ -74,44 +90,43 @@ export function percySnapshot(name, options) {

// Create a full-page DOM snapshot from the current testing page.
// TODO(fotinakis): more memory-efficient way to do this?
let domCopy = Ember.$('html').clone();
let testingContainer = domCopy.find('#ember-testing');
let domCopy = document.querySelector('html').cloneNode(true);
let testingContainer = domCopy.querySelector('#ember-testing');

if (scope) {
snapshotRoot = testingContainer.find(scope);
snapshotRoot = testingContainer.querySelector(scope);
} else {
snapshotRoot = testingContainer;
}

snapshotRoot = setAttributeValues(snapshotRoot);
snapshotRoot = setTextareaContent(snapshotRoot);

let snapshotHtml = snapshotRoot.html();
let snapshotHtml = snapshotRoot.innerHTML;

// Hoist the testing container contents up to the body.
// We need to use the original DOM to keep the head stylesheet around.
domCopy.find('body').html(snapshotHtml);
domCopy.querySelector('body').innerHTML = snapshotHtml;

domCopy = setTextareaContent(domCopy);

let { widths, breakpoints, enableJavaScript } = options;
let content = getDoctype() + domCopy.outerHTML;

Ember.run(function() {
maybeDisableMockjax();
Ember.$.ajax('/_percy/snapshot', {
xhr: getNativeXhr,
run(function() {
return ajax('/_percy/snapshot', {
mode: 'cors',
method: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
name: name,
content: getDoctype() + domCopy[0].outerHTML,
widths: options.widths,
breakpoints: options.breakpoints,
enableJavaScript: options.enableJavaScript,
}),
statusCode: {
400: function(jqXHR) {
// Bubble up 400 errors, ie. when given options are invalid.
throw jqXHR.responseText;
},
}
});
maybeResetMockjax();
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify({
name,
content,
widths,
breakpoints,
enableJavaScript,
})
})
.then(bubbleErrors);
});
}
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Test against the latest version of this Node.js version
environment:
matrix:
- nodejs_version: "4"
- nodejs_version: "6"
- nodejs_version: "8"

Expand All @@ -10,6 +11,7 @@ install:
- ps: Install-Product node $env:nodejs_version

- npm install -g yarn
- npm install -g bower
- npm install -g phantomjs-prebuilt

# install modules
Expand All @@ -20,6 +22,7 @@ test_script:
# Output useful info for debugging.
- node --version
- yarn --version
- bower --version
# run tests
- yarn build
- yarn test
Expand Down
3 changes: 1 addition & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"name": "ember-percy",
"dependencies": {
}
"dependencies": {}
}
Loading