Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 69e4efe

Browse files
author
Matt Goo
authored
feat(infrastructure): react router screenshots (#232)
1 parent d43115c commit 69e4efe

File tree

119 files changed

+788
-1316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+788
-1316
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ matrix:
3737
- docker pull mdcreact/screenshots
3838
- docker image ls
3939
script:
40-
- docker run -it --rm --cap-add=SYS_ADMIN -e MDC_GCLOUD_SERVICE_ACCOUNT_KEY="${MDC_GCLOUD_SERVICE_ACCOUNT_KEY}" mdcreact/screenshots /bin/sh -c "git fetch; git checkout \"${CURRENT_BRANCH}\"; git pull; npm i; /home/pptruser/material-components-web-react/test/screenshot/start.sh; sleep 330s; npm run test:image-diff"
40+
- docker run -it --rm --cap-add=SYS_ADMIN -e MDC_GCLOUD_SERVICE_ACCOUNT_KEY="${MDC_GCLOUD_SERVICE_ACCOUNT_KEY}" mdcreact/screenshots /bin/sh -c "git fetch; git checkout \"${CURRENT_BRANCH}\"; git pull; npm i; /home/pptruser/material-components-web-react/test/screenshot/start.sh; sleep 30s; npm run test:image-diff"

package-lock.json

Lines changed: 99 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"test:watch": "karma start karma.local.js --auto-watch",
1919
"test:unit": "npm run clean && NODE_ENV=test karma start karma.local.js --single-run",
2020
"test:unit-ci": "karma start karma.ci.js --single-run",
21-
"test:image-diff": "MDC_COMMIT_HASH=$(git rev-parse --short HEAD) MDC_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) mocha --compilers js:babel-core/register --ui tdd --timeout 90000 test/screenshot/diff-suite.js",
21+
"test:image-diff": "MDC_COMMIT_HASH=$(git rev-parse --short HEAD) MDC_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) mocha --compilers js:babel-core/register --ui tdd --timeout 10000 test/screenshot/diff-suite.js",
2222
"test:screenshots": "docker run -it --rm --cap-add=SYS_ADMIN -e MDC_GCLOUD_SERVICE_ACCOUNT_KEY=\"${MDC_GCLOUD_SERVICE_ACCOUNT_KEY}\" mdcreact/screenshots /bin/sh -c 'git checkout master; git pull; npm i; /home/pptruser/material-components-web-react/test/screenshot/start.sh; sleep 200s; npm run test:image-diff'",
2323
"upload:screenshots": "node ./test/screenshot/upload-screenshots.js"
2424
},
@@ -97,6 +97,7 @@
9797
"puppeteer": "^1.1.1",
9898
"react": "^16.4.2",
9999
"react-dom": "^16.4.2",
100+
"react-router-dom": "^4.3.1",
100101
"resemblejs": "^2.10.3",
101102
"sass-loader": "^6.0.7",
102103
"testdouble": "^3.6.0",

packages/select/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import React from 'react';
2424
import PropTypes from 'prop-types';
2525
import classnames from 'classnames';
26-
import {MDCSelectFoundation} from '@material/select';
26+
import {MDCSelectFoundation} from '@material/select/dist/mdc.select';
2727

2828
import FloatingLabel from '@material/react-floating-label';
2929
import LineRipple from '@material/react-line-ripple';

packages/webpack.config.js

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const webpack = require('webpack');
2424
const {readdirSync, lstatSync} = require('fs');
2525
const path = require('path');
2626
const ExtractTextPlugin = require('extract-text-webpack-plugin');
27-
27+
const {readMaterialPackages} = require('../scripts/package-json-reader');
28+
const {convertToImportPaths} = require('../scripts/package-name-converter');
2829
const {importer} = require('./webpack.util');
2930

3031
const isDirectory = (source) => lstatSync(source).isDirectory();
@@ -75,31 +76,10 @@ function getCommonWebpackParams(entryPath, chunk, {isCss, modules}) {
7576
}
7677

7778
function getMaterialExternals() {
78-
const dashedToCamel = (name) => name.replace(/-(\w)/g, (_, v) => v.toUpperCase());
7979
const externals = {};
80-
[
81-
'base',
82-
'button',
83-
'card',
84-
'chips',
85-
'fab',
86-
'floating-label',
87-
'line-ripple',
88-
'list',
89-
'notched-outline',
90-
'ripple',
91-
'select',
92-
'tab',
93-
'tab-indicator',
94-
'tab-scroller',
95-
'textfield',
96-
'top-app-bar',
97-
'typography',
98-
].forEach((name) => {
99-
// this can be reverted when we change back to @material/foo-package-filename
100-
// https://github.com/material-components/material-components-web/pull/3245
101-
const fileName = `@material/${name}/dist/mdc.${dashedToCamel(name)}`;
102-
externals[fileName] = fileName;
80+
const importPaths = convertToImportPaths(readMaterialPackages());
81+
importPaths.forEach((importPath) => {
82+
externals[importPath] = importPath;
10383
});
10484
return externals;
10585
}

scripts/package-json-reader.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs = require('fs');
2+
const {resolve, join} = require('path');
3+
const packageJson = JSON.parse(fs.readFileSync(resolve(__dirname, '../package.json'), 'utf8'));
4+
5+
6+
const readMaterialPackages = () => {
7+
const dependencies = [
8+
// must manually add any packages not in material-components-web-react/package.json
9+
'base',
10+
];
11+
12+
for (let dep in packageJson.devDependencies) {
13+
if (dep.startsWith('@material/')) {
14+
dependencies.push(dep);
15+
}
16+
}
17+
return dependencies;
18+
}
19+
20+
21+
module.exports = {readMaterialPackages};

scripts/package-name-converter.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const {basename} = require('path');
2+
3+
const dashedToCamel = (name) => name.replace(/-(\w)/g, (_, v) => v.toUpperCase());
4+
5+
const convertToImportPaths = (packageNames) => {
6+
const importPaths = [];
7+
return packageNames.map((packageName) => {
8+
const name = basename(packageName);
9+
// this can be reverted when we change back to @material/foo-package-filename
10+
// https://github.com/material-components/material-components-web/pull/3245
11+
return `@material/${name}/dist/mdc.${dashedToCamel(name)}`;
12+
});
13+
}
14+
15+
module.exports = {convertToImportPaths};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const {lstatSync, readdirSync} = require('fs');
2+
const {basename, join, resolve} = require('path');
3+
4+
const denyList = [
5+
'chips',
6+
'images'
7+
];
8+
const isDirectory = source => lstatSync(source).isDirectory();
9+
const getDirectories = source =>
10+
readdirSync(source).map(name => join(source, name)).filter(isDirectory);
11+
12+
function read(
13+
components = [],
14+
path = resolve(__dirname, '../test/screenshot'),
15+
parentDirectory = ''
16+
) {
17+
const directories = getDirectories(path);
18+
directories.forEach((directory) => {
19+
const packageName = basename(directory);
20+
if (denyList.includes(packageName)) return;
21+
22+
// recursively get sub directories
23+
const subDirectories = getDirectories(resolve(path, packageName));
24+
if (subDirectories.length > 0) {
25+
read(components, resolve(path, packageName), packageName);
26+
}
27+
components.push(`${parentDirectory ? parentDirectory + '/' : ''}${packageName}`);
28+
});
29+
30+
return components;
31+
}
32+
33+
module.exports = {read};

test/screenshot/App.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import {Link} from 'react-router-dom';
3+
4+
const convertPathNameToSpaces = (name) => name.replace(/-(\w)|\/(\w)/g, (_, first, second) => {
5+
// first is if the word has a `-` appended to the beginning
6+
// second i if the word has a `/` appended to the beginning
7+
return ` ${first ? first : second}`;
8+
});
9+
10+
const Home = () => {
11+
return (
12+
<div>
13+
{/* COMPONENTS is a global variable defined by webpack found in the
14+
webpack.DefinePlugin */}
15+
{COMPONENTS.sort().map((componentPath, index) => (
16+
<div key={index}>
17+
<Link to={componentPath}>{convertPathNameToSpaces(componentPath)}</Link>
18+
</div>
19+
))}
20+
</div>
21+
);
22+
};
23+
24+
export default Home;

test/screenshot/button/index.html

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)