Repository navigation
Expand file tree
/
Copy pathoutput-tests.js
More file actions
82 lines (73 loc) · 3.36 KB
/
Copy pathoutput-tests.js
File metadata and controls
82 lines (73 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import fs from 'fs';
import path from 'path';
import { expect } from 'chai';
import { CURRENT_CONFIG_VERSION } from '../constants.js';
function loadJSON(pathFromRoot) {
return JSON.parse(fs.readFileSync(path.join(import.meta.dirname, '..', pathFromRoot), 'utf-8'));
}
function fileNameToFeatureName(name) {
return name.replace(/[.]json$/, '').replace(/-([a-z0-9])/g, function (g) {
return g[1].toUpperCase();
});
}
/**
* Tests on the built config output. You'll need to run `npm run build` first for these tests to
* work.
*/
describe('Build output validation', () => {
describe('unprotected temporary merge', () => {
const extractDomains = (exception) => exception.domain;
const override = loadJSON('overrides/extension-override.json');
const config = loadJSON(`generated/v${CURRENT_CONFIG_VERSION}/extension-config.json`);
[
'content-blocking',
'cookie',
'click-to-load',
'web-compat',
].forEach((featureFile) => {
const feature = fileNameToFeatureName(featureFile);
const featureConfig = loadJSON(`features/${featureFile}.json`);
it(`${feature} should include platform unprotectedTemporary exceptions`, () => {
const expected = override.unprotectedTemporary.map(extractDomains);
const actual = config.features[feature].exceptions.map(extractDomains);
expected.forEach((domain) => {
expect(actual).to.contain(domain);
});
});
it(`${feature} should include feature exceptions`, () => {
const expected = featureConfig.exceptions.map(extractDomains);
const actual = config.features[feature].exceptions.map(extractDomains);
expected.forEach((domain) => {
expect(actual).to.contain(domain);
});
});
it(`${feature} exceptions should not contain duplicates`, () => {
expect(config.features[feature].exceptions.length).to.equal(
new Set(config.features[feature].exceptions.map(extractDomains)).size,
);
});
});
[
'ad-click-attribution',
'autofill',
].forEach((featureFile) => {
const feature = fileNameToFeatureName(featureFile);
const featureConfig = loadJSON(`features/${featureFile}.json`);
it(`${feature} should not include platform unprotectedTemporary exceptions`, () => {
const unprotected = new Set(override.unprotectedTemporary.map(extractDomains));
featureConfig.exceptions.map(extractDomains).forEach((domain) => unprotected.delete(domain));
const actual = config.features[feature].exceptions.map(extractDomains);
unprotected.forEach((domain) => {
expect(actual).to.not.contain(domain);
});
});
it(`${feature} should include feature exceptions`, () => {
const expected = featureConfig.exceptions.map(extractDomains);
const actual = config.features[feature].exceptions.map(extractDomains);
expected.forEach((domain) => {
expect(actual).to.contain(domain);
});
});
});
});
});