Skip to content

Commit

Permalink
Split init rules (#105)
Browse files Browse the repository at this point in the history
* Split initRules module is smaller units.

* Update .gitignore.

* Fix tests error in other browsers than Chrome.

* Run linting.

* Changes from feedback.

* Update tests format.

* Fix linting issues.

* 26.0.0
  • Loading branch information
dompuiu authored May 7, 2020
1 parent c0ef538 commit 2eec8bd
Show file tree
Hide file tree
Showing 91 changed files with 4,644 additions and 4,988 deletions.
26 changes: 21 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@
"jasmine": true,
"node": true
},
"extends": ["plugin:prettier/recommended"],
"rules": {
"camelcase": [2, {"properties": "always"}],
"indent": [2, 2, {"SwitchCase": 1}], // 2 spaces indentation
"camelcase": [2, { "properties": "always" }],
"indent": [2, 2, { "SwitchCase": 1 }], // 2 spaces indentation
"semi": [2, "always"],
"keyword-spacing": [2],
"space-before-function-paren": [2, "never"],
"space-before-function-paren": [
2,
{
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}
],
"space-before-blocks": [2, "always"],
"space-infix-ops": [2, {"int32Hint": false}],
"space-infix-ops": [2, { "int32Hint": false }],
"quotes": [1, "single", "avoid-escape"],
"max-len": [2, 100, 4, {"ignoreUrls": true, "ignorePattern": "^(\\s*(var|let|const)\\s.+=\\s*require\\s*\\()|(^\\s*import)"}],
"max-len": [
2,
100,
4,
{
"ignoreUrls": true,
"ignorePattern": "^(\\s*(var|let|const)\\s.+=\\s*require\\s*\\()|(^\\s*import)"
}
],
"eqeqeq": [2, "allow-null"],
"strict": [2, "global"],
"no-nested-ternary": [2],
Expand Down
2,133 changes: 891 additions & 1,242 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@adobe/reactor-turbine",
"version": "25.8.0",
"version": "26.0.0",
"description": "Launch rule engine which processes rules on client websites and delegates logic to extensions.",
"license": "Apache-2.0",
"scripts": {
"build": "rollup -c --intro \"if (!window.atob) { console.warn('Adobe Launch is unsupported in IE 9 and below.'); return; }\" && uglifyjs dist/engine.js -c -m -o dist/engine.min.js",
"build:watch": "rollup --watch -c --intro \"if (!window.atob) { console.warn('Adobe Launch is unsupported in IE 9 and below.'); return; }\" && uglifyjs dist/engine.js -c -m -o dist/engine.min.js",
"prepublishOnly": "npm run build",
"test": "karma start",
"test:watch": "npm test -- --no-single-run --no-coverage",
"test": "karma start && npm run lint",
"test:watch": "karma start --no-single-run --no-coverage",
"lint": "eslint 'src/**/*.js'"
},
"author": {
Expand All @@ -32,23 +32,26 @@
"devDependencies": {
"camelize": "1.0.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"inject-loader": "^4.0.1",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine-core": "^3.5.0",
"karma": "^4.4.1",
"karma": "^5.0.3",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.1",
"karma-coverage": "^2.0.2",
"karma-firefox-launcher": "^1.3.0",
"karma-jasmine": "^3.1.0",
"karma-jasmine": "^3.1.1",
"karma-jasmine-matchers": "^4.0.2",
"karma-safari-launcher": "^1.0.0",
"karma-sauce-launcher": "^2.0.2",
"karma-sauce-launcher": "^4.1.4",
"karma-webpack": "^4.0.2",
"kebab-case": "1.0.0",
"rollup": "^0.50.0",
"rollup-plugin-commonjs": "^8.2.4",
"rollup-plugin-node-resolve": "^3.0.0",
"webpack": "^4.41.5",
"yargs": "^15.1.0"
"prettier": "^2.0.5",
"rollup": "^2.7.5",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"webpack": "^4.43.0",
"yargs": "^15.3.1"
}
}
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default {
input: 'src/index.js',
output: {
file: 'dist/engine.js',
format: 'iife'
format: 'iife',
name: '_satellite'
},
name: '_satellite',
plugins: [
resolve({
preferBuiltins: false
Expand Down
23 changes: 7 additions & 16 deletions src/__tests__/buildRuleExecutionOrder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

var buildRuleExecutionOrder = require('../buildRuleExecutionOrder');

describe('buildRuleExecutionOrder', function() {
it('orders rules whose order is swapped in different events', function() {
describe('buildRuleExecutionOrder', function () {
it('orders rules whose order is swapped in different events', function () {
var ruleA = {
events: [
{
Expand All @@ -40,10 +40,7 @@ describe('buildRuleExecutionOrder', function() {
]
};

var executionOrder = buildRuleExecutionOrder([
ruleA,
ruleB
]);
var executionOrder = buildRuleExecutionOrder([ruleA, ruleB]);

expect(executionOrder).toEqual([
{
Expand All @@ -65,7 +62,7 @@ describe('buildRuleExecutionOrder', function() {
]);
});

it('maintains the natural order to no ruleOrder provided', function() {
it('maintains the natural order to no ruleOrder provided', function () {
// Note that we don't provide a default ruleOrder value. This is because ruleOrder will
// be required in the container schema. However, when users are testing things out in the
// sandbox, it's nice to be able to leave off ruleOrder and have the rules still execute
Expand Down Expand Up @@ -94,11 +91,7 @@ describe('buildRuleExecutionOrder', function() {
]
};

var exectionOrder = buildRuleExecutionOrder([
ruleA,
ruleB,
ruleC
]);
var exectionOrder = buildRuleExecutionOrder([ruleA, ruleB, ruleC]);

expect(exectionOrder).toEqual([
{
Expand All @@ -116,14 +109,12 @@ describe('buildRuleExecutionOrder', function() {
]);
});

it('handles rules with no events', function() {
it('handles rules with no events', function () {
var ruleA = {
events: []
};

var executionOrder = buildRuleExecutionOrder([
ruleA
]);
var executionOrder = buildRuleExecutionOrder([ruleA]);

expect(executionOrder).toEqual([]);
});
Expand Down
28 changes: 18 additions & 10 deletions src/__tests__/cleanText.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,32 @@

var textCleaner = require('../cleanText');

describe('cleanText', function() {
it('removes extra spaces from a string', function() {
expect(textCleaner('Clean multiple spaces')).toEqual('Clean multiple spaces');
describe('cleanText', function () {
it('removes extra spaces from a string', function () {
expect(textCleaner('Clean multiple spaces')).toEqual(
'Clean multiple spaces'
);
});

it('removes new lines from a string', function() {
expect(textCleaner('new line here \n and\nhere \n')).toEqual('new line here and here');
it('removes new lines from a string', function () {
expect(textCleaner('new line here \n and\nhere \n')).toEqual(
'new line here and here'
);
});

it('returns same string if no modifications need to be made', function() {
expect(textCleaner('This is my Perfect String')).toEqual('This is my Perfect String');
it('returns same string if no modifications need to be made', function () {
expect(textCleaner('This is my Perfect String')).toEqual(
'This is my Perfect String'
);
});

it('removes spaces from the beginning and end of a string', function() {
expect(textCleaner(' This is my String ')).toEqual('This is my String');
it('removes spaces from the beginning and end of a string', function () {
expect(textCleaner(' This is my String ')).toEqual(
'This is my String'
);
});

it('returns unmodified value it is not a string', function() {
it('returns unmodified value it is not a string', function () {
expect(textCleaner()).toBeUndefined();
expect(textCleaner(123)).toBe(123);
var obj = {};
Expand Down
30 changes: 15 additions & 15 deletions src/__tests__/createDebugController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,58 @@ governing permissions and limitations under the License.

var createDebugController = require('../createDebugController');

describe('function returned by createDebugController', function() {
describe('function returned by createDebugController', function () {
var localStorage;
var logger;

beforeEach(function() {
beforeEach(function () {
localStorage = jasmine.createSpyObj('localStorage', ['getItem', 'setItem']);
logger = {
outputEnabled: false
};
debugController = createDebugController(localStorage, logger);
});

it('returns whether debug is enabled', function() {
localStorage.getItem.and.returnValue("true");
it('returns whether debug is enabled', function () {
localStorage.getItem.and.returnValue('true');
var debugController = createDebugController(localStorage, logger);
expect(debugController.getDebugEnabled()).toBe(true);
localStorage.getItem.and.returnValue("false");
localStorage.getItem.and.returnValue('false');
expect(debugController.getDebugEnabled()).toBe(false);
});

it('persists debug changes', function() {
it('persists debug changes', function () {
var debugController = createDebugController(localStorage, logger);
localStorage.getItem.and.returnValue("false");
localStorage.getItem.and.returnValue('false');
debugController.setDebugEnabled(true);
expect(localStorage.setItem).toHaveBeenCalledWith('debug', true);
localStorage.getItem.and.returnValue("true");
localStorage.getItem.and.returnValue('true');
debugController.setDebugEnabled(false);
expect(localStorage.setItem).toHaveBeenCalledWith('debug', false);
});

it('calls onDebugChanged callbacks when debugging is toggled', function() {
it('calls onDebugChanged callbacks when debugging is toggled', function () {
var debugController = createDebugController(localStorage, logger);
var callback1 = jasmine.createSpy('callback1');

debugController.onDebugChanged(callback1);
debugController.setDebugEnabled(true);
localStorage.getItem.and.returnValue("true");
localStorage.getItem.and.returnValue('true');
expect(callback1).toHaveBeenCalledWith(true);

var callback2 = jasmine.createSpy('callback2');
debugController.onDebugChanged(callback2);
debugController.setDebugEnabled(false);
localStorage.getItem.and.returnValue("false");
localStorage.getItem.and.returnValue('false');
expect(callback1).toHaveBeenCalledWith(false);
expect(callback2).toHaveBeenCalledWith(false);
expect (callback1).toHaveBeenCalledTimes(2);
expect (callback2).toHaveBeenCalledTimes(1);
expect(callback1).toHaveBeenCalledTimes(2);
expect(callback2).toHaveBeenCalledTimes(1);

// Shouldn't call the callbacks again since debug
// hasn't actually changed.
debugController.setDebugEnabled(false);
expect (callback1).toHaveBeenCalledTimes(2);
expect (callback2).toHaveBeenCalledTimes(1);
expect(callback1).toHaveBeenCalledTimes(2);
expect(callback2).toHaveBeenCalledTimes(1);
});
});
Loading

0 comments on commit 2eec8bd

Please sign in to comment.