aboutsummaryrefslogtreecommitdiff
path: root/test/shared
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-07-13 22:36:56 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-07-13 22:36:56 +0900
commit944dea59199fa03f77e0e7c0d3c02acf8ccb458f (patch)
tree5f44471cdb32376a8c93e6f6eba738180f08c96f /test/shared
parent77b4e807e2a8b3e7ddb5f042719a34962a31b1c4 (diff)
parent28bfa3ac8124d3453cd539db26da4f4703e783df (diff)
Merge remote-tracking branch 'origin/master' into greenkeeper/css-loader-1.0.0
Diffstat (limited to 'test/shared')
-rw-r--r--test/shared/blacklists.test.js42
-rw-r--r--test/shared/store/index.test.js110
-rw-r--r--test/shared/versions/index.test.js40
-rw-r--r--test/shared/versions/storage.test.js28
4 files changed, 42 insertions, 178 deletions
diff --git a/test/shared/blacklists.test.js b/test/shared/blacklists.test.js
new file mode 100644
index 0000000..87e89c5
--- /dev/null
+++ b/test/shared/blacklists.test.js
@@ -0,0 +1,42 @@
+import { includes } from 'shared/blacklists';
+
+describe("shared/blacklist", () => {
+ it('matches by *', () => {
+ let blacklist = ['*'];
+
+ expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
+ })
+
+ it('matches by hostname', () => {
+ let blacklist = ['github.com'];
+
+ expect(includes(blacklist, 'https://github.com')).to.be.true;
+ expect(includes(blacklist, 'https://gist.github.com')).to.be.false;
+ expect(includes(blacklist, 'https://github.com/ueokande')).to.be.true;
+ expect(includes(blacklist, 'https://github.org')).to.be.false;
+ expect(includes(blacklist, 'https://google.com/search?q=github.org')).to.be.false;
+ })
+
+ it('matches by hostname with wildcard', () => {
+ let blacklist = ['*.github.com'];
+
+ expect(includes(blacklist, 'https://github.com')).to.be.false;
+ expect(includes(blacklist, 'https://gist.github.com')).to.be.true;
+ })
+
+ it('matches by path', () => {
+ let blacklist = ['github.com/abc'];
+
+ expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
+ expect(includes(blacklist, 'https://github.com/abcdef')).to.be.false;
+ expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false;
+ })
+
+ it('matches by path with wildcard', () => {
+ let blacklist = ['github.com/abc*'];
+
+ expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
+ expect(includes(blacklist, 'https://github.com/abcdef')).to.be.true;
+ expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false;
+ })
+});
diff --git a/test/shared/store/index.test.js b/test/shared/store/index.test.js
deleted file mode 100644
index 5b69b40..0000000
--- a/test/shared/store/index.test.js
+++ /dev/null
@@ -1,110 +0,0 @@
-import { createStore } from 'shared/store';
-
-describe("Store class", () => {
- const reducer = (state, action) => {
- if (state == undefined) {
- return 0;
- }
- return state + action;
- };
-
- describe("#dispatch", () => {
- it('transit status by immediate action', () => {
- let store = createStore(reducer);
- store.dispatch(10);
- expect(store.getState()).to.equal(10);
-
- store.dispatch(-20);
- expect(store.getState()).to.equal(-10);
- });
-
- it('returns next state by immediate action', () => {
- let store = createStore(reducer);
- let dispatchedAction = store.dispatch(11);
- expect(dispatchedAction).to.equal(11);
- });
-
- it('transit status by Promise action', () => {
- let store = createStore(reducer);
- let p1 = Promise.resolve(10);
-
- return store.dispatch(p1).then(() => {
- expect(store.getState()).to.equal(10);
- }).then(() => {
- store.dispatch(Promise.resolve(-20));
- }).then(() => {
- expect(store.getState()).to.equal(-10);
- });
- });
-
- it('returns next state by promise action', () => {
- let store = createStore(reducer);
- let dispatchedAction = store.dispatch(Promise.resolve(11));
- return dispatchedAction.then((value) => {
- expect(value).to.equal(11);
- });
- });
- });
-
- describe("#subscribe", () => {
- it('invoke callback', (done) => {
- let store = createStore(reducer);
- store.subscribe(() => {
- expect(store.getState()).to.equal(15);
- done();
- });
- store.dispatch(15);
- });
-
- it('propagate sender object', (done) => {
- let store = createStore(reducer);
- store.subscribe((sender) => {
- expect(sender).to.equal('sender');
- done();
- });
- store.dispatch(15, 'sender');
- });
- })
-
- describe("catcher", () => {
- it('catch an error in reducer on initializing by immediate action', (done) => {
- let store = createStore(() => {
- throw new Error();
- }, (e) => {
- expect(e).to.be.an('error');
- done();
- });
- });
-
- it('catch an error in reducer on initializing by immediate action', (done) => {
- let store = createStore((state, action) => {
- if (state === undefined) return 0;
- throw new Error();
- }, (e) => {
- expect(e).to.be.an('error');
- done();
- });
- store.dispatch(20);
- });
-
- it('catch an error in reducer on initializing by promise action', (done) => {
- let store = createStore((state, action) => {
- if (state === undefined) return 0;
- throw new Error();
- }, (e) => {
- expect(e).to.be.an('error');
- done();
- });
- store.dispatch(Promise.resolve(20));
- });
-
- it('catch an error in promise action', (done) => {
- let store = createStore((state, action) => 0, (e) => {
- expect(e).to.be.an('error');
- done();
- });
- store.dispatch(new Promise(() => { throw new Error() }));
- });
- })
-});
-
diff --git a/test/shared/versions/index.test.js b/test/shared/versions/index.test.js
deleted file mode 100644
index d90f04c..0000000
--- a/test/shared/versions/index.test.js
+++ /dev/null
@@ -1,40 +0,0 @@
-import * as versions from 'shared/versions';
-import manifest from '../../../manifest.json';
-
-describe("shared/versions/storage", () => {
- describe('#checkUpdated', () => {
- beforeEach(() => {
- return browser.storage.local.remove('version');
- });
-
- it('return true if no previous versions', async() => {
- let updated = await versions.checkUpdated();
- expect(updated).to.be.true;
- });
-
- it('return true if updated', async() => {
- await browser.storage.local.set({ version: '0.001' });
- let updated = await versions.checkUpdated();
- expect(updated).to.be.true;
- });
-
- it('return false if not updated', async() => {
- await browser.storage.local.set({ version: manifest.version });
- let updated = await versions.checkUpdated();
- expect(updated).to.be.false;
- });
- });
-
- describe('#commit', () => {
- beforeEach(() => {
- return browser.storage.local.remove('version');
- });
-
- it('saves current version from manifest.json', async() => {
- await versions.commit();
- let { version } = await browser.storage.local.get('version');
- expect(version).to.be.a('string');
- expect(version).to.equal(manifest.version);
- });
- });
-});
diff --git a/test/shared/versions/storage.test.js b/test/shared/versions/storage.test.js
deleted file mode 100644
index f541abf..0000000
--- a/test/shared/versions/storage.test.js
+++ /dev/null
@@ -1,28 +0,0 @@
-import * as storage from 'shared/versions/storage';
-
-describe("shared/versions/storage", () => {
- describe('#load', () => {
- beforeEach(() => {
- return browser.storage.local.remove('version');
- });
-
- it('loads saved version', async() => {
- await browser.storage.local.set({ version: '1.2.3' });
- let version = await storage.load();
- expect(version).to.equal('1.2.3');
- });
-
- it('returns undefined if no versions in storage', async() => {
- let version = await storage.load();
- expect(version).to.be.a('undefined');
- });
- });
-
- describe('#save', () => {
- it('saves version string', async() => {
- await storage.save('2.3.4');
- let { version } = await browser.storage.local.get('version');
- expect(version).to.equal('2.3.4');
- });
- });
-});