Skip to content

Commit 1e6508a

Browse files
committed
remove pagexray tests
1 parent 41ee904 commit 1e6508a

File tree

2 files changed

+8
-253
lines changed

2 files changed

+8
-253
lines changed

src/co2.test.js

Lines changed: 3 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,25 @@
11
"use strict";
22

3-
import fs from "fs";
4-
import path from "path";
5-
import { MILLION, ONEBYTE, SWD } from "./constants/test-constants.js";
6-
7-
import pagexray from "pagexray";
3+
import { MILLION, SWD } from "./constants/test-constants.js";
84

95
import CO2 from "./co2.js";
106
import { averageIntensity, marginalIntensity } from "./index.js";
117

128
const TwnGridIntensityValue = averageIntensity.data["TWN"];
139

1410
describe("co2", () => {
15-
let har, co2;
16-
describe("1 byte model", () => {
17-
const { TGWF_GREY_VALUE, TGWF_GREEN_VALUE, TGWF_MIXED_VALUE } = ONEBYTE;
18-
19-
beforeEach(() => {
20-
co2 = new CO2({ model: "1byte" });
21-
har = JSON.parse(
22-
fs.readFileSync(
23-
path.resolve(__dirname, "../data/fixtures/tgwf.har"),
24-
"utf8"
25-
)
26-
);
27-
});
28-
29-
describe("perPage", () => {
30-
it("returns CO2 for total transfer for page", () => {
31-
const pages = pagexray.convert(har);
32-
const pageXrayRun = pages[0];
33-
34-
expect(co2.perPage(pageXrayRun).toFixed(5)).toBe(
35-
TGWF_GREY_VALUE.toFixed(5)
36-
);
37-
});
38-
it("returns lower CO2 for page served from green site", () => {
39-
const pages = pagexray.convert(har);
40-
const pageXrayRun = pages[0];
41-
let green = [
42-
"www.thegreenwebfoundation.org",
43-
"fonts.googleapis.com",
44-
"ajax.googleapis.com",
45-
"assets.digitalclimatestrike.net",
46-
"cdnjs.cloudflare.com",
47-
"graphite.thegreenwebfoundation.org",
48-
"analytics.thegreenwebfoundation.org",
49-
"fonts.gstatic.com",
50-
"api.thegreenwebfoundation.org",
51-
];
52-
expect(co2.perPage(pageXrayRun, green)).toBeLessThan(TGWF_GREY_VALUE);
53-
});
54-
it("returns a lower CO2 number where *some* domains use green power", () => {
55-
const pages = pagexray.convert(har);
56-
const pageXrayRun = pages[0];
57-
// green can be true, or a array containing entries
58-
let green = [
59-
"www.thegreenwebfoundation.org",
60-
"fonts.googleapis.com",
61-
"ajax.googleapis.com",
62-
"assets.digitalclimatestrike.net",
63-
"cdnjs.cloudflare.com",
64-
"graphite.thegreenwebfoundation.org",
65-
"analytics.thegreenwebfoundation.org",
66-
"fonts.gstatic.com",
67-
"api.thegreenwebfoundation.org",
68-
];
69-
expect(co2.perPage(pageXrayRun, green).toFixed(5)).toBe(
70-
TGWF_MIXED_VALUE.toFixed(5)
71-
);
72-
});
73-
});
74-
describe("perDomain", () => {
75-
it("shows object listing Co2 for each domain", () => {
76-
const pages = pagexray.convert(har);
77-
const pageXrayRun = pages[0];
78-
const res = co2.perDomain(pageXrayRun);
79-
80-
const domains = [
81-
"thegreenwebfoundation.org",
82-
"www.thegreenwebfoundation.org",
83-
"maxcdn.bootstrapcdn.com",
84-
"fonts.googleapis.com",
85-
"ajax.googleapis.com",
86-
"assets.digitalclimatestrike.net",
87-
"cdnjs.cloudflare.com",
88-
"graphite.thegreenwebfoundation.org",
89-
"analytics.thegreenwebfoundation.org",
90-
"fonts.gstatic.com",
91-
"api.thegreenwebfoundation.org",
92-
];
93-
94-
for (let obj of res) {
95-
expect(domains.indexOf(obj.domain)).toBeGreaterThan(-1);
96-
expect(typeof obj.co2).toBe("number");
97-
}
98-
});
99-
it("shows lower Co2 for green domains", () => {
100-
const pages = pagexray.convert(har);
101-
const pageXrayRun = pages[0];
102-
103-
const greenDomains = [
104-
"www.thegreenwebfoundation.org",
105-
"fonts.googleapis.com",
106-
"ajax.googleapis.com",
107-
"assets.digitalclimatestrike.net",
108-
"cdnjs.cloudflare.com",
109-
"graphite.thegreenwebfoundation.org",
110-
"analytics.thegreenwebfoundation.org",
111-
"fonts.gstatic.com",
112-
"api.thegreenwebfoundation.org",
113-
];
114-
const res = co2.perDomain(pageXrayRun);
115-
const resWithGreen = co2.perDomain(pageXrayRun, greenDomains);
116-
117-
for (let obj of res) {
118-
expect(typeof obj.co2).toBe("number");
119-
}
120-
for (let obj of greenDomains) {
121-
let index = 0;
122-
expect(resWithGreen[index].co2).toBeLessThan(res[index].co2);
123-
index++;
124-
}
125-
});
126-
});
127-
});
11+
let co2;
12812

12913
describe("Sustainable Web Design model as simple option", () => {
13014
// the SWD model should have slightly higher values as
13115
// we include more of the system in calculations for the
13216
// same levels of data transfer
13317

134-
const {
135-
MILLION_GREEN,
136-
MILLION_GREY,
137-
TGWF_GREY_VALUE,
138-
TGWF_MIXED_VALUE,
139-
MILLION_PERVISIT_GREY,
140-
MILLION_PERVISIT_GREEN,
141-
} = SWD;
18+
const { MILLION_PERVISIT_GREY, MILLION_PERVISIT_GREEN } = SWD;
14219

14320
// We're not passing in a model parameter here to check that SWD is used by default
14421
beforeEach(() => {
14522
co2 = new CO2();
146-
har = JSON.parse(
147-
fs.readFileSync(
148-
path.resolve(__dirname, "../data/fixtures/tgwf.har"),
149-
"utf8"
150-
)
151-
);
15223
});
15324

15425
describe("perVisit", () => {
@@ -173,105 +44,6 @@ describe("co2", () => {
17344
});
17445
});
17546

176-
describe("perPage", () => {
177-
it("returns CO2 for total transfer for page", () => {
178-
const pages = pagexray.convert(har);
179-
const pageXrayRun = pages[0];
180-
181-
expect(parseFloat(co2.perPage(pageXrayRun).toFixed(5))).toBeCloseTo(
182-
parseFloat(TGWF_GREY_VALUE.toFixed(5)),
183-
3
184-
);
185-
});
186-
it("returns lower CO2 for page served from green site", () => {
187-
const pages = pagexray.convert(har);
188-
const pageXrayRun = pages[0];
189-
let green = [
190-
"www.thegreenwebfoundation.org",
191-
"fonts.googleapis.com",
192-
"ajax.googleapis.com",
193-
"assets.digitalclimatestrike.net",
194-
"cdnjs.cloudflare.com",
195-
"graphite.thegreenwebfoundation.org",
196-
"analytics.thegreenwebfoundation.org",
197-
"fonts.gstatic.com",
198-
"api.thegreenwebfoundation.org",
199-
];
200-
expect(co2.perPage(pageXrayRun, green)).toBeLessThan(TGWF_GREY_VALUE);
201-
});
202-
it("returns a lower CO2 number where *some* domains use green power", () => {
203-
const pages = pagexray.convert(har);
204-
const pageXrayRun = pages[0];
205-
// green can be true, or a array containing entries
206-
let green = [
207-
"www.thegreenwebfoundation.org",
208-
"fonts.googleapis.com",
209-
"ajax.googleapis.com",
210-
"assets.digitalclimatestrike.net",
211-
"cdnjs.cloudflare.com",
212-
"graphite.thegreenwebfoundation.org",
213-
"analytics.thegreenwebfoundation.org",
214-
"fonts.gstatic.com",
215-
"api.thegreenwebfoundation.org",
216-
];
217-
expect(
218-
parseFloat(co2.perPage(pageXrayRun, green).toFixed(5))
219-
).toBeCloseTo(parseFloat(TGWF_MIXED_VALUE.toFixed(5)), 3);
220-
});
221-
});
222-
describe("perDomain", () => {
223-
it("shows object listing Co2 for each domain", () => {
224-
const pages = pagexray.convert(har);
225-
const pageXrayRun = pages[0];
226-
const res = co2.perDomain(pageXrayRun);
227-
228-
const domains = [
229-
"thegreenwebfoundation.org",
230-
"www.thegreenwebfoundation.org",
231-
"maxcdn.bootstrapcdn.com",
232-
"fonts.googleapis.com",
233-
"ajax.googleapis.com",
234-
"assets.digitalclimatestrike.net",
235-
"cdnjs.cloudflare.com",
236-
"graphite.thegreenwebfoundation.org",
237-
"analytics.thegreenwebfoundation.org",
238-
"fonts.gstatic.com",
239-
"api.thegreenwebfoundation.org",
240-
];
241-
242-
for (let obj of res) {
243-
expect(domains.indexOf(obj.domain)).toBeGreaterThan(-1);
244-
expect(typeof obj.co2).toBe("number");
245-
}
246-
});
247-
it("shows lower Co2 for green domains", () => {
248-
const pages = pagexray.convert(har);
249-
const pageXrayRun = pages[0];
250-
251-
const greenDomains = [
252-
"www.thegreenwebfoundation.org",
253-
"fonts.googleapis.com",
254-
"ajax.googleapis.com",
255-
"assets.digitalclimatestrike.net",
256-
"cdnjs.cloudflare.com",
257-
"graphite.thegreenwebfoundation.org",
258-
"analytics.thegreenwebfoundation.org",
259-
"fonts.gstatic.com",
260-
"api.thegreenwebfoundation.org",
261-
];
262-
const res = co2.perDomain(pageXrayRun);
263-
const resWithGreen = co2.perDomain(pageXrayRun, greenDomains);
264-
265-
for (let obj of res) {
266-
expect(typeof obj.co2).toBe("number");
267-
}
268-
for (let obj of greenDomains) {
269-
let index = 0;
270-
expect(resWithGreen[index].co2).toBeLessThan(res[index].co2);
271-
index++;
272-
}
273-
});
274-
});
27547
describe("Returning results by segment", () => {
27648
const {
27749
MILLION_GREY,

src/hosting.test.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
"use strict";
22

3-
import fs from "fs";
43
import https from "https";
54
import path from "path";
65

7-
import pagexray from "pagexray";
8-
96
import hosting from "./hosting-node.js";
107

118
jest.mock("https");
@@ -25,35 +22,21 @@ describe("hosting", () => {
2522
let har;
2623
let httpsGetSpy;
2724
beforeEach(() => {
28-
har = JSON.parse(
29-
fs.readFileSync(
30-
path.resolve(__dirname, "../data/fixtures/tgwf.har"),
31-
"utf8"
32-
)
33-
);
3425
httpsGetSpy = jest.spyOn(https, "get");
3526
jest.clearAllMocks();
3627
});
3728
describe("checking all domains on a page object with #checkPage", () => {
3829
it("returns a list of green domains, when passed a page object", async () => {
39-
const pages = pagexray.convert(har);
40-
const pageXrayRun = pages[0];
4130
const db = await hosting.loadJSON(jsonPath);
42-
const greenDomains = await hosting.checkPage(pageXrayRun, db);
31+
const greenDomains = await hosting.checkPage(
32+
["www.thegreenwebfoundation.org", "fonts.googleapis.com"],
33+
db
34+
);
4335

44-
expect(greenDomains).toHaveLength(11);
36+
expect(greenDomains).toHaveLength(2);
4537
const expectedGreendomains = [
46-
"maxcdn.bootstrapcdn.com",
47-
"thegreenwebfoundation.org",
4838
"www.thegreenwebfoundation.org",
4939
"fonts.googleapis.com",
50-
"ajax.googleapis.com",
51-
"assets.digitalclimatestrike.net",
52-
"cdnjs.cloudflare.com",
53-
"graphite.thegreenwebfoundation.org",
54-
"analytics.thegreenwebfoundation.org",
55-
"fonts.gstatic.com",
56-
"api.thegreenwebfoundation.org",
5740
];
5841
greenDomains.forEach((dom) => {
5942
expect(expectedGreendomains).toContain(dom);

0 commit comments

Comments
 (0)