Skip to content

Commit

Permalink
v4.2.3 - 2020-03-02
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornstar committed Mar 2, 2020
1 parent cebd904 commit 03ab491
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 41 deletions.
30 changes: 30 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"no-console": "off",
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Intercept Redirect

## v4.2.3 - 2020-03-02
- Update `mocha` from `v7.0.1` to `v7.1.0`
- Add `eslint`
- Use Object.prototype.hasOwnProperty
- Fix typo in test description
- Split test into `mocha` and `eslint`
- Use arrow functions in tests
- Remove `browser extension` from keywords in `package.json`

## v4.2.2 - 2020-02-02
- Update all CI platforms to node v12
- `manifest.json` uses spaces instead of tabs or spaces
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"name": "@bjornstar/intercept-redirect",
"version": "4.2.2",
"version": "4.2.3",
"description": "Skip tracking redirects that serve no purpose other than to waste your valuable time.",
"main": "webextension/index.js",
"dependencies": {},
"devDependencies": {
"mocha": "^7.0.1"
"eslint": "^6.8.0",
"mocha": "^7.1.0"
},
"scripts": {
"build": "./build.sh",
"test": "mocha test"
"lint": "eslint webextension test",
"mocha": "mocha test",
"test": "npm run lint && npm run mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bjornstar/intercept-redirect.git"
},
"keywords": [
"webextension",
"browser extension",
"redirect"
],
"author": "Bjorn Stromberg <bjorn@bjornstar.com>",
Expand Down
70 changes: 35 additions & 35 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,76 +41,76 @@ const urls = [

const redirectUrl = 'https://bjornstar.com/intercept-redirect';

const manifestSites = manifest.permissions.filter(function (permission) {
const manifestSites = manifest.permissions.filter(permission => {
return permission !== 'webRequest' && permission !== 'webRequestBlocking';
}).map(function (site) {
}).map(site => {
return site.replace('*://', '').replace('/', '');
});

const testSites = urls.map(function (url) {
const testSites = urls.map(url => {
const host = url.substring(8, url.indexOf('/', 8));
return subdomain(host);
});

const webExtensionSites = Object.keys(webExtension.sites);

describe('analyzeURL', function () {
describe('Each URL redirects to the correct location', function () {
urls.forEach(function (url) {
it(`url: ${url}`, function () {
describe('analyzeURL', () => {
describe('Each URL redirects to the correct location', () => {
urls.forEach(url => {
it(`url: ${url}`, () => {
assert.deepEqual(analyzeURL({ url }), { redirectUrl });
});
});
});

describe('No redirect for sites that are implemented but the URLs do not match', function () {
describe('No redirect for sites that are implemented but the URLs do not match', () => {
const url = 'https://www.google.com/';

it(`url: ${url}`, function () {
it(`url: ${url}`, () => {
assert.ok(!analyzeURL({ url }));
});
});

describe('No redirect for sites that are not implemented', function () {
describe('No redirect for sites that are not implemented', () => {
const url = 'https://bjornstar.com/';

it(`url: ${url}`, function () {
it(`url: ${url}`, () => {
assert.ok(!analyzeURL({ url }));
});
});
});

describe('Packaging', function () {
describe('Every site implemented in the webExtension is in the manifest permissions', function () {
webExtensionSites.forEach(function (site) {
it(`site: ${site}`, function () {
describe('Packaging', () => {
describe('Every site implemented in the webExtension is in the manifest permissions', () => {
webExtensionSites.forEach(site => {
it(`site: ${site}`, () => {
assert.ok(manifestSites.indexOf(site) !== -1, `Unmatched: ${site}`);
});
});
});

describe('Every site in the manifest permissions is implemented in the webExension', function () {
manifestSites.forEach(function (site) {
it (`site: ${site}`, function () {
describe('Every site in the manifest permissions is implemented in the webExtension', () => {
manifestSites.forEach(site => {
it (`site: ${site}`, () => {
assert.ok(webExtensionSites.indexOf(site) !== -1, `Unmatched: ${site}`);
});
});
});

describe('Every site implemented in the webExtension has a test', function () {
manifestSites.forEach(function (site) {
it(`site: ${site}`, function () {
describe('Every site implemented in the webExtension has a test', () => {
manifestSites.forEach(site => {
it(`site: ${site}`, () => {
assert.ok(testSites.indexOf(site) !== -1, `Missing tests: ${site}`);
});
});
})
});

it('Version number is the same in both the package and manifest', function () {
it('Version number is the same in both the package and manifest', () => {
assert.equal(manifest.version, pkg.version);
});

it('The CHANGELOG has an entry for the current version', function (done) {
fs.readFile(path.resolve('./CHANGELOG.md'), 'utf8', function (error, changelog) {
it('The CHANGELOG has an entry for the current version', done => {
fs.readFile(path.resolve('./CHANGELOG.md'), 'utf8', (error, changelog) => {
if (error) return done(error);

const lines = changelog.split('\n');
Expand All @@ -121,45 +121,45 @@ describe('Packaging', function () {
const line = lines[i];

if (versionRe.test(line)) {
assert.equal(line.indexOf(versionLine), 0, `Package: ${versionLine}, Latest CHANGELOG: ${line}`)
return done()
assert.equal(line.indexOf(versionLine), 0, `Package: ${versionLine}, Latest CHANGELOG: ${line}`);
return done();
}
}

done(new Error('No version found in CHANGELOG'));
});
});

it('The manifest does not use tabs', function (done) {
fs.readFile(path.resolve('./webextension/manifest.json'), 'utf8', function (error, manifest) {
it('The manifest does not use tabs', done => {
fs.readFile(path.resolve('./webextension/manifest.json'), 'utf8', (error, manifest) => {
if (error) return done(error);

const lines = manifest.split('\n');
const whitespaceRe = /^(\s+)/
const whitespaceRe = /^(\s+)/;

lines.forEach((line, index) => {
const match = line.match(whitespaceRe);
assert(!match || !match[0].includes("\t"), `Found a tab on line ${index+1}`);
assert(!match || !match[0].includes('\t'), `Found a tab on line ${index+1}`);
});

done();
});
});
});

describe('Subdomain', function () {
it(`For supported domains returns *.domain`, function () {
describe('Subdomain', () => {
it('For supported domains returns *.domain', () => {
assert.equal(subdomain('foobar.digidip.net'), '*.digidip.net');
assert.equal(subdomain('foo.bar.digidip.net'), '*.digidip.net');
assert.equal(subdomain('wow.curseforge.com'), '*.curseforge.com');
});

it('Does not apply to domain host', function () {
it('Does not apply to domain host', () => {
assert.equal(subdomain('digidip.net'), 'digidip.net');
assert.equal(subdomain('curseforge.com'), 'curseforge.com');
});

it('Returns host when not supported', function () {
it('Returns host when not supported', () => {
assert.equal(subdomain('intercept-redirect.bjornstar.com'), 'intercept-redirect.bjornstar.com');
assert.equal(subdomain('bjornstar.com'), 'bjornstar.com');
});
Expand Down
6 changes: 6 additions & 0 deletions webextension/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"env": {
"browser": true,
"webextensions": true
}
}
2 changes: 1 addition & 1 deletion webextension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function reduceKeyValues(o, pair) {

function findKey(o, keys = []) {
for (let i = 0; i < keys.length; i += 1) {
if (o.hasOwnProperty(keys[i])) {
if (Object.prototype.hasOwnProperty.call(o, keys[i])) {
return o[keys[i]];
}
}
Expand Down
2 changes: 1 addition & 1 deletion webextension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
"*://workable.com/",
"*://www.youtube.com/"
],
"version": "4.2.2"
"version": "4.2.3"
}

0 comments on commit 03ab491

Please sign in to comment.