t.test('should match exact', q => { const script = buildScript({ meta: { match: [ 'https://www.google.com/a/b/c', ], }, }); q.ok(testScript('https://www.google.com/a/b/c', script), 'should match exact'); q.notOk(testScript('https://www.google.com/a/b/c/d', script), 'should match exact'); q.end(); });
t.test('should match all', q => { const script = buildScript({ meta: { match: [ '*://*/*', ], }, }); q.ok(testScript('https://www.google.com/', script), 'should match `http | https`'); q.notOk(testScript('file:///Users/Gerald/file', script), 'should not match `file`'); q.end(); });
t.test('should match any', q => { const script = buildScript({ meta: { match: [ 'https://www.google.com/*', ], }, }); q.ok(testScript('https://www.google.com/', script), 'should match `/`'); q.ok(testScript('https://www.google.com/hello/world', script), 'should match any'); q.end(); });
t.test('should include any', q => { const script = buildScript({ meta: { include: [ '*', ], }, }); q.ok(testScript('https://www.google.com/', script), 'should match `http | https`'); q.ok(testScript('file:///Users/Gerald/file', script), 'should match `file`'); q.end(); });
t.test('should match domain', q => { const script = buildScript({ meta: { match: [ '*://docs.google.com/', ], }, }); q.ok(testScript('https://docs.google.com/', script), 'should match exact domain name'); q.notOk(testScript('https://sub.docs.google.com/', script), 'should not match subdomains'); q.notOk(testScript('https://docs.google.com.cn/', script), 'should not match suffixed domains'); q.end(); });
t.test('should support magic TLD', q => { const script = buildScript({ meta: { exclude: [ 'https://www.google.tld/*', ], }, }); q.notOk(testScript('https://www.google.com/', script), 'should match `.com`'); q.notOk(testScript('https://www.google.com.hk/', script), 'should match `.com.hk`'); q.ok(testScript('https://www.google.example.com/', script), 'should not match subdomains'); q.end(); });
t.test('should match subdomains', q => { const script = buildScript({ meta: { match: [ '*://*.google.com/', ], }, }); q.ok(testScript('https://www.google.com/', script), 'should match subdomains'); q.ok(testScript('https://a.b.google.com/', script), 'should match subdomains'); q.ok(testScript('https://google.com/', script), 'should match specified domain'); q.notOk(testScript('https://www.google.com.hk/', script), 'should not match suffixed domains'); q.end(); });
t.test('should include by regexp', q => { const script = buildScript({ meta: { include: [ 'https://www.google.com/*', 'https://twitter.com/*', ], }, }); q.ok(testScript('https://www.google.com/', script), 'should match `/`'); q.ok(testScript('https://www.google.com/hello/world', script), 'include by prefix'); q.notOk(testScript('https://www.hello.com/', script), 'not include by prefix'); q.end(); });
t.test('should ignore original rules', q => { const script = buildScript({ custom: { match: [ 'https://twitter.com/*', ], }, meta: { match: [ 'https://www.google.com/*', ], }, }); q.ok(testScript('https://twitter.com/', script), 'should match custom rules'); q.notOk(testScript('https://www.google.com/', script), 'should not match original rules'); q.end(); });
t.test('should exclude any', q => { const script = buildScript({ meta: { match: [ '*://*/*', ], excludeMatch: [ '*://*/*', ], }, }); q.notOk(testScript('https://www.google.com/', script), 'should exclude `http | https`'); q.end(); });