diff --git a/.travis.yml b/.travis.yml index b3eceea70..ccb987775 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,12 @@ matrix: install: npm i script: npm run lint + #TODO(issues/936): Fix existing errors before requiring this to pass + #- node_js: 10 + # env: TEST_SUITE=types + # install: npm i + # script: npm run test:types + - node_js: 10 install: npm i services: diff --git a/docs/contributions/running-tests.md b/docs/contributions/running-tests.md index 707fa32cc..16e370557 100644 --- a/docs/contributions/running-tests.md +++ b/docs/contributions/running-tests.md @@ -63,3 +63,13 @@ npm run lint ``` This will print any lines that do not follow the eslint standards, which you will need to fix before opeing a PR. + +## Type Tests + +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): + +```bash +npm run test:types +``` + +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. diff --git a/package.json b/package.json index 0cb798f98..6428da367 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "test:unit-ci": "karma start karma.ci.js --single-run", "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", "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'", + "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", "upload:screenshots": "node ./test/screenshot/upload-screenshots.js" }, "config": { diff --git a/test/types/gen-index.js b/test/types/gen-index.js new file mode 100644 index 000000000..c9920da0e --- /dev/null +++ b/test/types/gen-index.js @@ -0,0 +1,38 @@ +// The MIT License +// +// Copyright (c) 2019 Google, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +/** + * @fileoverview Generates index.ts file with imports for all repo packages. + */ + +const {join} = require('path'); +const {readdirSync, statSync, writeFileSync} = require('fs'); + +let out = 'import "react";\n'; +const dir = 'packages'; +for (const subdir of readdirSync(dir)) { + if (!statSync(join(dir, subdir)).isDirectory()) { + continue; + } + out += 'import "@material/react-' + subdir + '";\n'; +} +writeFileSync('test/types/index.ts', out, 'ascii');