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

Commit 1f7f872

Browse files
Ari ChivukulaMatt Goo
Ari Chivukula
authored and
Matt Goo
committed
feat(infrastructure): add typescript production typings test (#900)
1 parent bf3ea77 commit 1f7f872

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ matrix:
2222
install: npm i
2323
script: npm run lint
2424

25+
#TODO(issues/936): Fix existing errors before requiring this to pass
26+
#- node_js: 10
27+
# env: TEST_SUITE=types
28+
# install: npm i
29+
# script: npm run test:types
30+
2531
- node_js: 10
2632
install: npm i
2733
services:

docs/contributions/running-tests.md

+10
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,13 @@ npm run lint
6363
```
6464

6565
This will print any lines that do not follow the eslint standards, which you will need to fix before opeing a PR.
66+
67+
## Type Tests
68+
69+
Due to [multiple issues in production type files](https://github.com/material-components/material-components-web-react/issues/936) an easy way to [validate production type files has been added](https://github.com/material-components/material-components-web-react/pull/900):
70+
71+
```bash
72+
npm run test:types
73+
```
74+
75+
This command will perform a full production build, install the locally built versions, [generate a file that imports them all](../../test/types/gen-index.js), and then build it to expose any issues in the locally built `.d.ts` files.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"test:unit-ci": "karma start karma.ci.js --single-run",
2020
"test:image-diff": "MDC_COMMIT_HASH=$(git rev-parse --short HEAD) MDC_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) mocha --require ts-node/register --require babel-core/register --ui tdd --timeout 60000 test/screenshot/diff-suite.tsx",
2121
"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 .; git checkout master; git pull; npm i; /home/pptruser/material-components-web-react/test/screenshot/start.sh; sleep 40s; npm run test:image-diff'",
22+
"test:types": "npm run build && node scripts/release/cp-pkgs.js && rm -rf packages/*/node_modules && npm install packages/ripple && ls -d ./packages/*/ | xargs -n1 -I{} npm install {} && node test/types/gen-index.js && cp tsconfig.json test/types/tsconfig.json && tsc --project test/types",
2223
"upload:screenshots": "node ./test/screenshot/upload-screenshots.js"
2324
},
2425
"config": {

test/types/gen-index.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// The MIT License
2+
//
3+
// Copyright (c) 2019 Google, Inc.
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
23+
/**
24+
* @fileoverview Generates index.ts file with imports for all repo packages.
25+
*/
26+
27+
const {join} = require('path');
28+
const {readdirSync, statSync, writeFileSync} = require('fs');
29+
30+
let out = 'import "react";\n';
31+
const dir = 'packages';
32+
for (const subdir of readdirSync(dir)) {
33+
if (!statSync(join(dir, subdir)).isDirectory()) {
34+
continue;
35+
}
36+
out += 'import "@material/react-' + subdir + '";\n';
37+
}
38+
writeFileSync('test/types/index.ts', out, 'ascii');

0 commit comments

Comments
 (0)