From f953cbdba45c6259664ae0b3ea2d198098d8923d Mon Sep 17 00:00:00 2001 From: James Henry Date: Sun, 28 Jul 2019 15:40:27 -0400 Subject: [PATCH] test: ensure integration tests can fail, add vue-sfc (#768) --- package.json | 2 +- .../eslint-plugin-tslint/src/rules/config.ts | 2 +- tests/integration/docker-compose.yml | 17 +++++ .../test.js.snap | 1 + .../fixtures/vue-sfc/.eslintrc.yml | 21 +++++++ tests/integration/fixtures/vue-sfc/Dockerfile | 17 +++++ tests/integration/fixtures/vue-sfc/Hello.vue | 36 +++++++++++ .../integration/fixtures/vue-sfc/test.js.snap | 63 +++++++++++++++++++ tests/integration/fixtures/vue-sfc/test.sh | 22 +++++++ .../fixtures/vue-sfc/tsconfig.json | 5 ++ tests/integration/run-all-tests.sh | 11 ++++ 11 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 tests/integration/fixtures/vue-sfc/.eslintrc.yml create mode 100644 tests/integration/fixtures/vue-sfc/Dockerfile create mode 100644 tests/integration/fixtures/vue-sfc/Hello.vue create mode 100644 tests/integration/fixtures/vue-sfc/test.js.snap create mode 100755 tests/integration/fixtures/vue-sfc/test.sh create mode 100644 tests/integration/fixtures/vue-sfc/tsconfig.json create mode 100755 tests/integration/run-all-tests.sh diff --git a/package.json b/package.json index 4e630cb4b1b..98a6c27fc2d 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "generate-contributors": "yarn ts-node ./tools/generate-contributors.ts && yarn all-contributors generate", "format": "prettier --write \"./**/*.{ts,js,json,md}\"", "format-check": "prettier --list-different \"./**/*.{ts,js,json,md}\"", - "integration-tests": "docker-compose -f tests/integration/docker-compose.yml up", + "integration-tests": "./tests/integration/run-all-tests.sh", "kill-integration-test-containers": "docker-compose -f tests/integration/docker-compose.yml down -v --rmi local", "lint": "eslint . --ext .js,.ts", "lint-fix": "eslint . --ext .js,.ts --fix", diff --git a/packages/eslint-plugin-tslint/src/rules/config.ts b/packages/eslint-plugin-tslint/src/rules/config.ts index 7152d21f69b..23ff428111d 100644 --- a/packages/eslint-plugin-tslint/src/rules/config.ts +++ b/packages/eslint-plugin-tslint/src/rules/config.ts @@ -69,7 +69,7 @@ export default createRule({ }, type: 'problem', messages: { - failure: '{{message}} (tslint:{{ruleName}})`', + failure: '{{message}} (tslint:{{ruleName}})', }, schema: [ { diff --git a/tests/integration/docker-compose.yml b/tests/integration/docker-compose.yml index 086f3e76485..5d10d766177 100644 --- a/tests/integration/docker-compose.yml +++ b/tests/integration/docker-compose.yml @@ -19,3 +19,20 @@ services: - /usr/eslint-plugin-tslint/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. - ./fixtures/typescript-and-tslint-plugins-together:/usr/linked + + vue-sfc: + build: ./fixtures/vue-sfc + container_name: "vue-sfc" + volumes: + # Runtime link to the relevant built @typescript-eslint packages and integration test utils, + # but apply an empty volume for the package tests, we don't need those. + - ../../package.json/:/usr/root-package.json + - ./utils/:/usr/utils + - ../../packages/parser/:/usr/parser + - /usr/parser/tests + - ../../packages/typescript-estree/:/usr/typescript-estree + - /usr/typescript-estree/tests + - ../../packages/eslint-plugin/:/usr/eslint-plugin + - /usr/eslint-plugin/tests + # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. + - ./fixtures/vue-sfc:/usr/linked diff --git a/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.js.snap b/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.js.snap index a4df7d29fe6..078ddadc167 100644 --- a/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.js.snap +++ b/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.js.snap @@ -24,6 +24,7 @@ Array [ "endLine": 1, "line": 1, "message": "Missing semicolon (tslint:semicolon)", + "messageId": "failure", "nodeType": null, "ruleId": "@typescript-eslint/tslint/config", "severity": 2, diff --git a/tests/integration/fixtures/vue-sfc/.eslintrc.yml b/tests/integration/fixtures/vue-sfc/.eslintrc.yml new file mode 100644 index 00000000000..f20f5baf174 --- /dev/null +++ b/tests/integration/fixtures/vue-sfc/.eslintrc.yml @@ -0,0 +1,21 @@ +root: true + +parser: 'vue-eslint-parser' + +env: + es6: true + node: true + +parserOptions: + # Local version of @typescript-eslint/parser + parser: '@typescript-eslint/parser' + project: /usr/linked/tsconfig.json + sourceType: module + extraFileExtensions: ['.vue'] + +plugins: +# Local version of @typescript-eslint/eslint-plugin +- '@typescript-eslint' + +rules: + '@typescript-eslint/no-explicit-any': 'error' diff --git a/tests/integration/fixtures/vue-sfc/Dockerfile b/tests/integration/fixtures/vue-sfc/Dockerfile new file mode 100644 index 00000000000..3b281e624c8 --- /dev/null +++ b/tests/integration/fixtures/vue-sfc/Dockerfile @@ -0,0 +1,17 @@ +FROM node:carbon + +# Copy the test.sh into the container. Every other file will be linked, rather +# than copied to allow for changes without rebuilds wherever possible +WORKDIR /usr +COPY ./test.sh /usr/ + +# Create file which will be executed by jest +# to assert that the lint output is what we expect +RUN echo "const actualLintOutput = require('./lint-output.json');\n" \ + "\n" \ + "test('it should produce the expected lint ouput', () => {\n" \ + " expect(actualLintOutput).toMatchSnapshot();\n" \ + "});\n" > test.js + +# Run the integration test +CMD [ "./test.sh" ] diff --git a/tests/integration/fixtures/vue-sfc/Hello.vue b/tests/integration/fixtures/vue-sfc/Hello.vue new file mode 100644 index 00000000000..1f5c59ed2dc --- /dev/null +++ b/tests/integration/fixtures/vue-sfc/Hello.vue @@ -0,0 +1,36 @@ + + + + diff --git a/tests/integration/fixtures/vue-sfc/test.js.snap b/tests/integration/fixtures/vue-sfc/test.js.snap new file mode 100644 index 00000000000..49bd30cc389 --- /dev/null +++ b/tests/integration/fixtures/vue-sfc/test.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`it should produce the expected lint ouput 1`] = ` +Array [ + Object { + "errorCount": 1, + "filePath": "/usr/linked/Hello.vue", + "fixableErrorCount": 0, + "fixableWarningCount": 0, + "messages": Array [ + Object { + "column": 29, + "endColumn": 32, + "endLine": 31, + "line": 31, + "message": "Unexpected any. Specify a different type.", + "messageId": "unexpectedAny", + "nodeType": "TSAnyKeyword", + "ruleId": "@typescript-eslint/no-explicit-any", + "severity": 2, + }, + ], + "source": " + + + +", + "warningCount": 0, + }, +] +`; diff --git a/tests/integration/fixtures/vue-sfc/test.sh b/tests/integration/fixtures/vue-sfc/test.sh new file mode 100755 index 00000000000..ba89362dcd1 --- /dev/null +++ b/tests/integration/fixtures/vue-sfc/test.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Generate the package.json to use +node /usr/utils/generate-package-json.js + +# Install dependencies +npm install + +# Use the local volumes for our own packages +npm install $(npm pack /usr/typescript-estree | tail -1) +npm install $(npm pack /usr/parser | tail -1) +npm install $(npm pack /usr/eslint-plugin | tail -1) + +# Install the latest vue-eslint-parser (this may break us occassionally, but it's probably good to get that feedback early) +npm install vue-eslint-parser@latest + +# Run the linting +# (the "|| true" helps make sure that we run our tests on failed linting runs as well) +npx eslint --format json --output-file /usr/lint-output.json --config /usr/linked/.eslintrc.yml /usr/linked/**/*.vue || true + +# Run our assertions against the linting output +npx jest /usr/test.js --snapshotResolver=/usr/utils/jest-snapshot-resolver.js diff --git a/tests/integration/fixtures/vue-sfc/tsconfig.json b/tests/integration/fixtures/vue-sfc/tsconfig.json new file mode 100644 index 00000000000..86423f3e4aa --- /dev/null +++ b/tests/integration/fixtures/vue-sfc/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "strict": true + } +} \ No newline at end of file diff --git a/tests/integration/run-all-tests.sh b/tests/integration/run-all-tests.sh new file mode 100755 index 00000000000..5b43af06246 --- /dev/null +++ b/tests/integration/run-all-tests.sh @@ -0,0 +1,11 @@ +# Ensure child script failures are propagated +set -e + +# We run the services serially and in a non-detached state just that we can ensure predictable +# exit codes for all of our integration tests, and we can ensure CI builds pass or fail appropriately + +# typescript-and-tslint-plugins-together +docker-compose -f tests/integration/docker-compose.yml up --build --abort-on-container-exit typescript-and-tslint-plugins-together + +# vue-sfc +docker-compose -f tests/integration/docker-compose.yml up --build --abort-on-container-exit vue-sfc