Skip to content

Commit d1b8091

Browse files
committed
test cleanups
1 parent e31f4b6 commit d1b8091

File tree

5 files changed

+13
-40
lines changed

5 files changed

+13
-40
lines changed

packages/container-query/src/Container.spec.js

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import Container from "./Container";
22
import { QUERIES } from "@zeecoder/container-query-meta-builder";
3+
import raf from "raf";
4+
import processMeta from "./processMeta";
5+
import adjustContainer from "./adjustContainer";
6+
import containerRegistry from "./containerRegistry";
7+
import ResizeObserver from "resize-observer-polyfill";
8+
import MutationObserver from "mutation-observer";
39

410
console.warn = jest.fn();
511
jest.mock("./processMeta", () => jest.fn(config => config));
@@ -35,26 +41,18 @@ jest.mock("mutation-observer", () => {
3541
});
3642

3743
beforeEach(() => {
38-
require("raf").mockClear();
39-
require("./processMeta").mockClear();
40-
require("./adjustContainer").mockClear();
41-
const ResizeObserver = require("resize-observer-polyfill");
44+
raf.mockClear();
45+
processMeta.mockClear();
46+
adjustContainer.mockClear();
4247
ResizeObserver.prototype.observe.mockClear();
4348
ResizeObserver.prototype.unobserve.mockClear();
44-
const containerRegistry = require("./containerRegistry");
4549
containerRegistry.get.mockClear();
4650
containerRegistry.set.mockClear();
4751
containerRegistry.has.mockClear();
4852
containerRegistry.delete.mockClear();
4953
});
5054

5155
test("should instantiate properly", () => {
52-
const ResizeObserver = require("resize-observer-polyfill");
53-
const processMeta = require("./processMeta");
54-
const adjustContainer = require("./adjustContainer");
55-
const containerRegistry = require("./containerRegistry");
56-
const raf = require("raf");
57-
5856
const containerElement = {
5957
parentNode: document.createElement("div")
6058
};
@@ -84,8 +82,6 @@ test("should instantiate properly", () => {
8482
});
8583

8684
test("should create the initial query state based on the number of queries", () => {
87-
const containerRegistry = require("./containerRegistry");
88-
8985
const containerElement = {
9086
parentNode: document.createElement("div")
9187
};
@@ -103,11 +99,6 @@ test("should create the initial query state based on the number of queries", ()
10399
});
104100

105101
test("should not call adjust if disabled by the options", () => {
106-
const ResizeObserver = require("resize-observer-polyfill");
107-
const processMeta = require("./processMeta");
108-
const adjustContainer = require("./adjustContainer");
109-
const raf = require("raf");
110-
111102
const containerElement = {
112103
parentNode: document.createElement("div")
113104
};
@@ -128,10 +119,6 @@ test("should not call adjust if disabled by the options", () => {
128119
});
129120

130121
test("should be able to observe resize events and switch off initial adjust call", () => {
131-
const ResizeObserver = require("resize-observer-polyfill");
132-
const raf = require("raf");
133-
const adjustContainer = require("./adjustContainer");
134-
135122
const containerElement = {
136123
parentNode: document.createElement("div")
137124
};
@@ -165,7 +152,6 @@ test("should be able to observe resize events and switch off initial adjust call
165152
});
166153

167154
test("should call adjust() on resize changes", () => {
168-
const containerRegistry = require("./containerRegistry");
169155
const randomElement = document.createElement("div");
170156
containerRegistry.get.mockImplementationOnce(queriedContainerElement => {
171157
expect(queriedContainerElement).toBe(randomElement);
@@ -177,7 +163,6 @@ test("should call adjust() on resize changes", () => {
177163

178164
return registryData;
179165
});
180-
const ResizeObserver = require("resize-observer-polyfill");
181166
const parentElement = document.createElement("div");
182167
const containerElement = document.createElement("div");
183168
parentElement.appendChild(containerElement);
@@ -232,10 +217,7 @@ test("should call adjust() on resize changes", () => {
232217
});
233218

234219
test("should clean up after container element is detached from the DOM", () => {
235-
const containerRegistry = require("./containerRegistry");
236220
containerRegistry.has.mockImplementationOnce(() => true);
237-
const MutationObserver = require("mutation-observer");
238-
const ResizeObserver = require("resize-observer-polyfill");
239221
ResizeObserver.prototype.unobserve = jest.fn();
240222
const parentElement = document.createElement("div");
241223
const containerElement = document.createElement("div");

packages/container-query/src/getChangedStyles.spec.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
STYLES,
77
VALUES
88
} from "@zeecoder/container-query-meta-builder";
9+
import containerRegistry from "./containerRegistry";
910

1011
jest.mock("./containerRegistry", () => ({
1112
get: jest.fn()
@@ -18,7 +19,6 @@ test("should return empty object if the element is not registered", () => {
1819
});
1920

2021
test("should apply default queries without a condition function", () => {
21-
const containerRegistry = require("./containerRegistry");
2222
containerRegistry.get.mockImplementation(() => {
2323
return {
2424
instance: { opts: { valuePrecision: 3 } },
@@ -124,7 +124,6 @@ test("should return change sets on first run", () => {
124124
}
125125
};
126126

127-
const containerRegistry = require("./containerRegistry");
128127
containerRegistry.get.mockImplementation(() => registryData);
129128

130129
const element = document.createElement("div");
@@ -223,7 +222,6 @@ test("should generate remove change set", () => {
223222
}
224223
};
225224

226-
const containerRegistry = require("./containerRegistry");
227225
containerRegistry.get.mockImplementation(() => registryData);
228226

229227
const element = document.createElement("div");
@@ -296,7 +294,6 @@ test("should generate empty change set if conditions allow", () => {
296294
}
297295
};
298296

299-
const containerRegistry = require("./containerRegistry");
300297
containerRegistry.get.mockImplementation(() => registryData);
301298

302299
const element = document.createElement("div");
@@ -362,7 +359,6 @@ test("should always recalculate values", () => {
362359
]
363360
}
364361
};
365-
const containerRegistry = require("./containerRegistry");
366362
containerRegistry.get.mockImplementation(() => registryData);
367363

368364
const element = document.createElement("div");
@@ -406,7 +402,6 @@ test("should be able to limit the precision of generated css values", () => {
406402
}
407403
};
408404

409-
const containerRegistry = require("./containerRegistry");
410405
containerRegistry.get.mockImplementation(() => registryData);
411406

412407
const element = document.createElement("div");
@@ -470,7 +465,6 @@ test("should handle multiple prop removal over multiple queries", () => {
470465
}
471466
};
472467

473-
const containerRegistry = require("./containerRegistry");
474468
containerRegistry.get.mockImplementation(() => registryData);
475469

476470
const element = document.createElement("div");
@@ -507,7 +501,6 @@ test("should use :self if the selector is not available", () => {
507501
}
508502
};
509503

510-
const containerRegistry = require("./containerRegistry");
511504
containerRegistry.get.mockImplementation(() => registryData);
512505

513506
const element = document.createElement("div");

packages/container-query/src/processMeta.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import {
44
CONDITIONS,
55
SELECTOR
66
} from "@zeecoder/container-query-meta-builder";
7+
import getConditionFunction from "./getConditionFunction";
78

89
jest.mock("./getConditionFunction");
910

1011
test("should turn conditions to functions", () => {
11-
const getConditionFunction = require("./getConditionFunction").default;
1212
getConditionFunction
1313
.mockImplementationOnce(() => () => 1)
1414
.mockImplementationOnce(() => () => 2)

packages/postcss-container-query/src/containerQuery.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as missingContainerDelcarationTest from "./test/missing-container-decla
99
import * as missingDeclarationWithRUnitsTest from "./test/missing-declaration-with-r-units";
1010
import * as selfTest from "./test/self";
1111
import * as simpleTest from "./test/simple";
12+
import fs from "fs";
1213

1314
const containerQuery = require("../dist");
1415
const getMetadataFromMessages = require("../getMetadataFromMessages");
@@ -66,7 +67,6 @@ test('should avoid accidentally creating ".default" exports', () => {
6667
});
6768

6869
test("should use the default json saving function if none was supplied", () => {
69-
const fs = require("fs");
7070
const pluginInstance = containerQuery();
7171

7272
pluginInstance(new Root(), { messages: [] });

packages/postcss-container-query/src/saveMeta.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import saveMeta from "./saveMeta";
2+
import fs from "fs";
23

34
jest.mock("fs");
45

56
test("should write contents when file does not exist", () => {
6-
const fs = require("fs");
77
const cssFilePath = __dirname + "/tmp/saveMeta.test.css";
88
const jsonFilePath = `${cssFilePath}.json`;
99
const json = { some: "JSON" };
@@ -24,7 +24,6 @@ test("should write contents when file does not exist", () => {
2424
});
2525

2626
test("should not write contents when file already with same contents", () => {
27-
const fs = require("fs");
2827
const cssFilePath = __dirname + "/tmp/saveMeta.test.css";
2928
const jsonFilePath = `${cssFilePath}.json`;
3029
const json = { some: "JSON" };
@@ -43,7 +42,6 @@ test("should not write contents when file already with same contents", () => {
4342
});
4443

4544
test("should log error in case there's an issue writing the file", () => {
46-
const fs = require("fs");
4745
const cssFilePath = __dirname + "/tmp/saveMeta.test.css";
4846
const jsonFilePath = `${cssFilePath}.json`;
4947
const json = { some: "JSON" };

0 commit comments

Comments
 (0)