Skip to content

Commit 27b02bb

Browse files
committed
First integration tests
1 parent 505fd83 commit 27b02bb

File tree

10 files changed

+980
-1773
lines changed

10 files changed

+980
-1773
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Integration tests, supported by SauceLabs
13+
1014
### Changed
1115

1216
- Removed unnecessary files from the packages
17+
- `react-container-query`
18+
- **[BREAKING]**ContainerQuery no longer returns an object for size, but width and height as
19+
the first parameter of the child function
20+
- **[BREAKING]** ContainerQuery now returns 1x1 dimensions before the ResizeObserver kicks in
1321

1422
### Removed
1523

16-
- Removed test running from Node 6
24+
- **[BREAKING]** Removed test running from Node 6
1725

1826
## [3.0.0-alpha.2]
1927

package.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
},
1313
"devDependencies": {
1414
"@babel/core": "^7.2.0",
15+
"@babel/preset-env": "^7.2.3",
16+
"@babel/preset-react": "^7.0.0",
17+
"autoprefixer": "^9.4.3",
1518
"babel-core": "^7.0.0-bridge.0",
1619
"babel-jest": "^23.6.0",
20+
"babel-loader": "^8.0.4",
21+
"babel-plugin-transform-class-properties": "^6.24.1",
1722
"babel-regenerator-runtime": "^6.5.0",
1823
"coveralls": "^3.0.2",
24+
"css-loader": "^2.0.2",
1925
"husky": "^1.1.4",
2026
"jasmine-core": "^3.3.0",
2127
"jest": "^23.6.0",
@@ -27,17 +33,23 @@
2733
"karma-spec-reporter": "^0.0.32",
2834
"lerna": "^3.4.3",
2935
"lint-staged": "^8.0.5",
30-
"parcel-bundler": "^1.10.3",
36+
"postcss-loader": "^3.0.0",
37+
"postcss-media-minmax": "^4.0.0",
38+
"postcss-nested": "^4.1.1",
3139
"prettier": "^1.15.2",
3240
"react": "^16.6.3",
3341
"react-dom": "^16.6.3",
34-
"regenerator-runtime": "^0.13.1"
42+
"regenerator-runtime": "^0.13.1",
43+
"style-loader": "^0.23.1",
44+
"webpack": "^4.28.2",
45+
"webpack-cli": "^3.1.2"
3546
},
3647
"scripts": {
3748
"test:unit": "jest --coverage",
3849
"test:unit:watch": "jest --watch",
3950
"test:integration": "karma start",
40-
"test:integration:build": "parcel build tests/index.js --out-dir tests/dist",
51+
"test:integration:watch": "yarn test:integration:build --watch",
52+
"test:integration:build": "webpack --config tests/webpack.config.js",
4153
"coveralls": "cat ./coverage/lcov.info | coveralls",
4254
"prettify": "prettier --write 'packages/**/*.js'",
4355
"bootstrap": "lerna bootstrap",

packages/react-container-query/src/ContainerQuery.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ContainerQuery extends Component {
1414
}
1515
}
1616

17-
state = { width: 0, height: 0 };
17+
state = { width: 1, height: 1 };
1818

1919
ref = React.createRef();
2020

@@ -52,7 +52,7 @@ class ContainerQuery extends Component {
5252

5353
doRender() {
5454
if (typeof this.props.children === "function") {
55-
return this.props.children(this.state);
55+
return this.props.children(this.state.width, this.state.height);
5656
} else if (this.props.children) {
5757
return this.props.children;
5858
}

tests/.babelrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"browsers": [">1%"]
8+
}
9+
}
10+
],
11+
"@babel/preset-react"
12+
]
13+
}

tests/index.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
import React from "react";
2-
import ReactDOM from "react-dom";
31
// Using the following to support async/await in tests.
42
// I'm intentionally not using babel/polyfill, as that would introduce polyfills
53
// the actual lib might not have, giving the false impression that something
64
// works while it might actually not, if you use the lib without babel-polyfill.
75
import "babel-regenerator-runtime";
8-
9-
const Test = () => <div id="asd" style={{ background: "grey" }} />;
10-
11-
it("should render", async () => {
12-
const div = document.createElement("div");
13-
document.body.appendChild(div);
14-
15-
ReactDOM.render(<Test />, div);
16-
17-
const rendered = document.querySelector("#asd");
18-
19-
expect(rendered.style.backgroundColor).toBe("grey");
20-
});
6+
import "./react";

tests/react/Basic/Basic.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { Component } from "react";
2+
import { ContainerQuery } from "../../../packages/react-container-query/dist/bundle.esm";
3+
import { meta as rawMeta } from "./Basic.pcss";
4+
5+
// todo this shouldn't be needed
6+
const meta = JSON.parse(rawMeta.slice(1, -1));
7+
8+
const Basic = () => (
9+
<ContainerQuery meta={meta} className="Basic" id="rendered-component">
10+
{(width, height) => {
11+
return (
12+
<div>
13+
{width}x{height}
14+
</div>
15+
);
16+
}}
17+
</ContainerQuery>
18+
);
19+
20+
export default Basic;

tests/react/Basic/Basic.pcss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.Basic {
2+
color: white;
3+
width: 101px;
4+
height: 100px;
5+
background-color: red;
6+
7+
@container (width > 100px) {
8+
background-color: green;
9+
}
10+
}

tests/react/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import Basic from "./Basic/Basic";
4+
5+
const delay = time => new Promise(resolve => setTimeout(resolve, time));
6+
7+
it("should render Basic", async () => {
8+
const div = document.createElement("div");
9+
document.body.appendChild(div);
10+
11+
ReactDOM.render(<Basic />, div);
12+
13+
const rendered = document.getElementById("rendered-component");
14+
15+
// Assertions before the ResizeObserver kicks in
16+
expect(rendered.textContent).toBe("1x1");
17+
18+
// wait a little before asserting
19+
await delay(50);
20+
21+
expect(rendered.textContent).toBe("101x100");
22+
expect(rendered.style.backgroundColor).toBe("green");
23+
});

tests/webpack.config.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module.exports = {
2+
entry: __dirname + "/index.js",
3+
output: {
4+
path: __dirname + "/dist",
5+
filename: "index.js"
6+
},
7+
mode: "development",
8+
module: {
9+
rules: [
10+
{
11+
test: /\.js$/,
12+
use: [
13+
{
14+
loader: "babel-loader",
15+
options: {
16+
presets: [
17+
"@babel/preset-react",
18+
[
19+
"@babel/preset-env",
20+
{
21+
targets: {
22+
browsers: [">1%"]
23+
}
24+
}
25+
]
26+
],
27+
plugins: ["transform-class-properties"]
28+
}
29+
}
30+
]
31+
},
32+
{
33+
test: /\.pcss$/,
34+
use: [
35+
"style-loader",
36+
"css-loader",
37+
{
38+
loader: "postcss-loader",
39+
options: {
40+
plugins: [
41+
require("postcss-nested")({ bubble: ["container"] }),
42+
require("postcss-media-minmax")(),
43+
require("autoprefixer")(),
44+
require("../packages/postcss-container-query/dist")()
45+
]
46+
}
47+
}
48+
]
49+
}
50+
]
51+
},
52+
devtool: "source-map"
53+
};

0 commit comments

Comments
 (0)