From a357415f6cdfe1b16c4881def00b4a6fb4b9bccf Mon Sep 17 00:00:00 2001 From: Jordi Marimon Date: Sun, 13 Aug 2023 10:54:26 +0200 Subject: [PATCH] test: update all tests because of prettier --- .eslintignore | 1 - .prettierignore | 3 +-- package.json | 7 ++--- scripts/{bump.mjs => bump.js} | 0 ...eference.mjs => generate-api-reference.js} | 0 scripts/prepare.js | 23 ++++++++++++++++ scripts/prepare.sh | 12 --------- tests/class/abstract/output.json | 12 ++++----- tests/class/abstract/test.ts | 12 ++++++--- tests/class/basic/output.json | 22 ++++++++-------- tests/class/basic/test.ts | 12 ++++++--- tests/class/class-expressions/output.json | 8 +++--- tests/class/class-expressions/test.ts | 12 ++++++--- tests/class/default-inheritance/output.json | 2 +- tests/class/default-inheritance/test.ts | 12 ++++++--- tests/class/extends-clause/output.json | 26 +++++++++---------- tests/class/extends-clause/test.ts | 12 ++++++--- tests/class/implements-clause/output.json | 8 +++--- tests/class/implements-clause/test.ts | 12 ++++++--- tests/class/inheritance/output.json | 8 +++--- tests/class/inheritance/test.ts | 12 ++++++--- tests/class/initializers/output.json | 14 +++++----- tests/class/initializers/test.ts | 12 ++++++--- tests/class/method-overload/output.json | 14 +++++----- tests/class/method-overload/test.ts | 12 ++++++--- tests/class/property-accessors/output.json | 12 ++++----- tests/class/property-accessors/test.ts | 12 ++++++--- .../class/third-party-inheritance/output.json | 10 +++---- tests/class/third-party-inheritance/test.ts | 12 ++++++--- .../output.json | 2 +- .../typed-parameters-and-inheritance/test.ts | 12 ++++++--- tests/decorator/accessor/output.json | 24 ++++++++++------- tests/decorator/accessor/test.ts | 12 ++++++--- tests/decorator/class/output.json | 14 +++++----- tests/decorator/class/test.ts | 12 ++++++--- tests/decorator/method/output.json | 18 +++++++------ tests/decorator/method/test.ts | 12 ++++++--- tests/decorator/parameter/output.json | 6 ++--- tests/decorator/parameter/test.ts | 12 ++++++--- tests/decorator/property/output.json | 16 +++++++----- tests/decorator/property/test.ts | 12 ++++++--- tests/enum/basic/output.json | 2 +- tests/enum/basic/test.ts | 12 ++++++--- tests/enum/initializers/output.json | 2 +- tests/enum/initializers/test.ts | 12 ++++++--- tests/export/default/output.json | 2 +- tests/export/default/test.ts | 12 ++++++--- tests/export/named/output.json | 2 +- tests/export/named/test.ts | 12 ++++++--- tests/export/namespace/output.json | 2 +- tests/export/namespace/test.ts | 12 ++++++--- tests/export/renamed/output.json | 2 +- tests/export/renamed/test.ts | 12 ++++++--- tests/export/star/output.json | 2 +- tests/export/star/test.ts | 12 ++++++--- tests/export/type/output.json | 4 +-- tests/export/type/test.ts | 12 ++++++--- tests/from-glob/output.json | 8 +++--- tests/from-glob/test.ts | 14 +++++++--- tests/from-project/basic/output.json | 2 +- tests/from-project/basic/test.ts | 14 +++++++--- .../test-project/packages/a/output.json | 2 +- .../test-project/packages/b/output.json | 16 ++++++------ tests/from-project/monorepo/test.ts | 12 ++++++--- tests/from-source/output.json | 2 +- tests/from-source/test.ts | 17 ++++++++---- tests/function/anonymous/output.json | 2 +- tests/function/anonymous/test.ts | 12 ++++++--- tests/function/arrow/output.json | 2 +- tests/function/arrow/test.ts | 12 ++++++--- tests/function/async/output.json | 2 +- tests/function/async/test.ts | 12 ++++++--- tests/function/basic/output.json | 2 +- tests/function/basic/test.ts | 12 ++++++--- .../const-type-parameters/output.json | 4 +-- tests/function/const-type-parameters/test.ts | 12 ++++++--- tests/function/generator/output.json | 2 +- tests/function/generator/test.ts | 12 ++++++--- tests/function/named-parameters/output.json | 2 +- tests/function/named-parameters/test.ts | 12 ++++++--- tests/function/overload/output.json | 2 +- tests/function/overload/test.ts | 12 ++++++--- tests/import/default/output.json | 4 +-- tests/import/default/test.ts | 12 ++++++--- tests/import/multiple/output.json | 8 +++--- tests/import/multiple/test.ts | 12 ++++++--- tests/import/named/output.json | 4 +-- tests/import/named/test.ts | 12 ++++++--- tests/import/namespace/output.json | 4 +-- tests/import/namespace/test.ts | 12 ++++++--- tests/import/paths/index.ts | 3 ++- tests/import/paths/output.json | 6 ++--- tests/import/paths/test.ts | 12 ++++++--- tests/import/side-effect/output.json | 2 +- tests/import/side-effect/test.ts | 12 ++++++--- tests/import/type/output.json | 6 ++--- tests/import/type/test.ts | 12 ++++++--- tests/interface/accessors/output.json | 8 +++--- tests/interface/accessors/test.ts | 12 ++++++--- tests/interface/basic/output.json | 2 +- tests/interface/basic/test.ts | 12 ++++++--- tests/interface/index-signature/output.json | 2 +- tests/interface/index-signature/test.ts | 12 ++++++--- tests/interface/method-overload/output.json | 2 +- tests/interface/method-overload/test.ts | 12 ++++++--- .../output.json | 2 +- .../typed-parameters-and-inheritance/test.ts | 12 ++++++--- tests/interface/utility-types/output.json | 2 +- tests/interface/utility-types/test.ts | 12 ++++++--- tests/jsdoc/description/output.json | 6 ++--- tests/jsdoc/description/test.ts | 12 ++++++--- tests/jsdoc/ignore/output.json | 2 +- tests/jsdoc/ignore/test.ts | 12 ++++++--- tests/jsdoc/tags/output.json | 2 +- tests/jsdoc/tags/test.ts | 12 ++++++--- tests/mixin/general-use-case/test.ts | 12 ++++++--- tests/mixin/mixin-builder/test.ts | 12 ++++++--- tests/namespace/basic/output.json | 22 ++++++++-------- tests/namespace/basic/test.ts | 12 ++++++--- tests/namespace/nested/output.json | 4 +-- tests/namespace/nested/test.ts | 12 ++++++--- tests/type-alias/basic/output.json | 2 +- tests/type-alias/basic/test.ts | 12 ++++++--- tests/type-alias/type-parameters/output.json | 2 +- tests/type-alias/type-parameters/test.ts | 12 ++++++--- tests/utils.ts | 13 ++++++++-- tests/variable/basic/output.json | 8 +++--- tests/variable/basic/test.ts | 12 ++++++--- tests/variable/complex-types/output.json | 18 ++++++------- tests/variable/complex-types/test.ts | 12 ++++++--- .../identifier-as-initializer/output.json | 8 +++--- .../identifier-as-initializer/test.ts | 12 ++++++--- .../variable/imported-initializer/output.json | 4 +-- tests/variable/imported-initializer/test.ts | 12 ++++++--- tests/variable/satisfies-operator/output.json | 18 ++++++------- tests/variable/satisfies-operator/test.ts | 12 ++++++--- tests/variable/type-alias/output.json | 2 +- tests/variable/type-alias/test.ts | 12 ++++++--- tests/variable/type-assertion/output.json | 2 +- tests/variable/type-assertion/test.ts | 12 ++++++--- 140 files changed, 861 insertions(+), 436 deletions(-) rename scripts/{bump.mjs => bump.js} (100%) rename scripts/docs/{generate-api-reference.mjs => generate-api-reference.js} (100%) create mode 100755 scripts/prepare.js delete mode 100755 scripts/prepare.sh diff --git a/.eslintignore b/.eslintignore index 453adef4..1b4c2f78 100644 --- a/.eslintignore +++ b/.eslintignore @@ -7,7 +7,6 @@ /bazel-out /e2e/out packages/*/dist/ -packages/*/.tsbuildinfo packages/*/package-lock.json # Node diff --git a/.prettierignore b/.prettierignore index b978c273..8759688b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,7 +7,6 @@ /bazel-out /e2e/out packages/*/dist/ -packages/*/.tsbuildinfo packages/*/package-lock.json # Node @@ -51,8 +50,8 @@ trace.zip .env _site/ +tests/**/*.json docs/**/*.css docs/**/*.njk scripts/**/*.hbs -docs/api-reference/**/*.njk diff --git a/package.json b/package.json index 9f9d379e..9997ee13 100644 --- a/package.json +++ b/package.json @@ -27,17 +27,18 @@ "doc:clear": "rm -rf ./_site", "doc:build:11ty": "NODE_ENV=production eleventy --config=.eleventy.cjs", "doc:start:11ty": "eleventy --serve --config=.eleventy.cjs", - "doc:api": "node scripts/docs/generate-api-reference.mjs", + "doc:api": "node scripts/docs/generate-api-reference.js", "ts:build": "tsc --build packages/*/tsconfig.json", "ts:reset": "rm -rf ./packages/*/.tsbuildinfo", "ts:clear": "rm -rf ./packages/*/dist", "publish": "npm publish --access public --workspaces", "test": "vitest run --config vitest.config.ts", + "test:update": "UPDATE_SNAPSHOTS=true vitest run --config vitest.config.ts", "coverage": "vitest run --coverage --config vitest.config.ts", - "prepare": "./scripts/prepare.sh", + "prepare": "node scripts/prepare.js", "upgrade": "rm -rf node_modules package-lock.json && npm i", "bump": "npx ncu -u -x typescript", - "bump:pkg": "node ./scripts/bump.mjs", + "bump:pkg": "node scripts/bump.js", "lint": "eslint \"**/*.ts\" --max-warnings 0", "lint:fix": "eslint \"**/*.ts\" --fix --cache --max-warnings 0", "prettier": "prettier --write --ignore-unknown" diff --git a/scripts/bump.mjs b/scripts/bump.js similarity index 100% rename from scripts/bump.mjs rename to scripts/bump.js diff --git a/scripts/docs/generate-api-reference.mjs b/scripts/docs/generate-api-reference.js similarity index 100% rename from scripts/docs/generate-api-reference.mjs rename to scripts/docs/generate-api-reference.js diff --git a/scripts/prepare.js b/scripts/prepare.js new file mode 100755 index 00000000..c09d873c --- /dev/null +++ b/scripts/prepare.js @@ -0,0 +1,23 @@ +import * as cp from 'child_process'; +import * as fs from 'fs'; + +// Execute Git command +const git = args => cp.spawnSync('git', args, { stdio: 'inherit' }); + +// Ensure that we're inside a Git repository +// If git command is not found, status is null and we should return +// That's why status value needs to be checked explicitly +if (git(['rev-parse']).status !== 0) { + throw new Error('git command not found, skipping install'); +} + +// Ensure that cwd is git top level +if (!fs.existsSync('.git')) { + throw new Error('.git can\'t be found'); +} + +const { error } = git(['config', 'core.hooksPath', '.hooks']); + +if (error) { + throw error; +} diff --git a/scripts/prepare.sh b/scripts/prepare.sh deleted file mode 100755 index 925637f2..00000000 --- a/scripts/prepare.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -if [[ ! -d ".git" ]] -then - echo "Current directory is not a valid git directory."; - exit 1; -fi - -git config core.hooksPath .hooks; - -chmod ug+x .hooks/*; -chmod ug+x .git/hooks/*; diff --git a/tests/class/abstract/output.json b/tests/class/abstract/output.json index 263bc5a6..f45cf921 100644 --- a/tests/class/abstract/output.json +++ b/tests/class/abstract/output.json @@ -17,7 +17,7 @@ "text": "number", "kind": "Primitive" }, - "line": 3, + "line": 2, "default": 4 }, { @@ -27,7 +27,7 @@ "text": "number", "kind": "Primitive" }, - "line": 5, + "line": 4, "abstract": true } ], @@ -43,7 +43,7 @@ "kind": "Primitive" } }, - "line": 7, + "line": 6, "parameters": [ { "name": "x", @@ -51,7 +51,7 @@ "text": "number", "kind": "Primitive" }, - "line": 7 + "line": 6 }, { "name": "y", @@ -59,7 +59,7 @@ "text": "number", "kind": "Primitive" }, - "line": 7 + "line": 6 } ] } @@ -76,4 +76,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/abstract/test.ts b/tests/class/abstract/test.ts index 30edd10a..63b17c90 100644 --- a/tests/class/abstract/test.ts +++ b/tests/class/abstract/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'abstract'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/basic/output.json b/tests/class/basic/output.json index 15d4cec6..5a004acc 100644 --- a/tests/class/basic/output.json +++ b/tests/class/basic/output.json @@ -20,7 +20,7 @@ } } }, - "line": 18, + "line": 17, "parameters": [ { "name": "x", @@ -28,7 +28,7 @@ "text": "number", "kind": "Primitive" }, - "line": 18 + "line": 17 }, { "name": "y", @@ -36,7 +36,7 @@ "text": "number", "kind": "Primitive" }, - "line": 18 + "line": 17 }, { "name": "message", @@ -44,7 +44,7 @@ "text": "string", "kind": "Primitive" }, - "line": 18 + "line": 17 } ] } @@ -63,7 +63,7 @@ "text": "number", "kind": "Primitive" }, - "line": 8, + "line": 7, "optional": true }, { @@ -73,7 +73,7 @@ "text": "string", "kind": "Primitive" }, - "line": 12, + "line": 11, "readOnly": true } ], @@ -85,7 +85,7 @@ "text": "\"Hello World\"", "kind": "Literal" }, - "line": 6, + "line": 5, "default": "'Hello World'", "static": true, "readOnly": true @@ -103,7 +103,7 @@ "kind": "Primitive" } }, - "line": 24, + "line": 23, "parameters": [ { "name": "message", @@ -111,7 +111,7 @@ "text": "string", "kind": "Primitive" }, - "line": 24 + "line": 23 } ] } @@ -129,7 +129,7 @@ "kind": "Primitive" } }, - "line": 28 + "line": 27 } ] } @@ -143,4 +143,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/basic/test.ts b/tests/class/basic/test.ts index 76596124..d295e866 100644 --- a/tests/class/basic/test.ts +++ b/tests/class/basic/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'basic'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/class-expressions/output.json b/tests/class/class-expressions/output.json index ab1322ee..855ba185 100644 --- a/tests/class/class-expressions/output.json +++ b/tests/class/class-expressions/output.json @@ -22,7 +22,7 @@ "text": "string", "kind": "Primitive" }, - "line": 6, + "line": 5, "default": "'foo'" } ] @@ -30,7 +30,7 @@ { "name": "bar", "kind": "Class", - "line": 13, + "line": 11, "jsDoc": [ { "kind": "description", @@ -45,7 +45,7 @@ "text": "string", "kind": "Primitive" }, - "line": 15, + "line": 12, "default": "'bar'" } ] @@ -62,4 +62,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/class-expressions/test.ts b/tests/class/class-expressions/test.ts index ee4a5e06..a6f0498c 100644 --- a/tests/class/class-expressions/test.ts +++ b/tests/class/class-expressions/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, updateExpectedOutput, test } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'class-expressions'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/default-inheritance/output.json b/tests/class/default-inheritance/output.json index 3217e217..7453f7c6 100644 --- a/tests/class/default-inheritance/output.json +++ b/tests/class/default-inheritance/output.json @@ -71,4 +71,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/default-inheritance/test.ts b/tests/class/default-inheritance/test.ts index 61624988..deef6423 100644 --- a/tests/class/default-inheritance/test.ts +++ b/tests/class/default-inheritance/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, updateExpectedOutput, test } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'default-inheritance'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/extends-clause/output.json b/tests/class/extends-clause/output.json index 936db679..4baf4083 100644 --- a/tests/class/extends-clause/output.json +++ b/tests/class/extends-clause/output.json @@ -16,7 +16,7 @@ "text": "number", "kind": "Primitive" }, - "line": 3, + "line": 2, "default": 4 } ], @@ -32,7 +32,7 @@ "kind": "Primitive" } }, - "line": 5, + "line": 4, "parameters": [ { "name": "x", @@ -40,7 +40,7 @@ "text": "number", "kind": "Primitive" }, - "line": 5 + "line": 4 }, { "name": "y", @@ -48,7 +48,7 @@ "text": "number", "kind": "Primitive" }, - "line": 5 + "line": 4 } ] } @@ -59,7 +59,7 @@ { "name": "Foo", "kind": "Class", - "line": 10, + "line": 9, "heritage": [ { "name": "Bar", @@ -78,7 +78,7 @@ "text": "number", "kind": "Primitive" }, - "line": 12, + "line": 10, "default": 3, "override": true } @@ -95,7 +95,7 @@ "kind": "Primitive" } }, - "line": 14, + "line": 12, "parameters": [ { "name": "x", @@ -103,7 +103,7 @@ "text": "number", "kind": "Primitive" }, - "line": 14 + "line": 12 }, { "name": "y", @@ -111,7 +111,7 @@ "text": "number", "kind": "Primitive" }, - "line": 14 + "line": 12 } ] } @@ -129,7 +129,7 @@ "kind": "Primitive" } }, - "line": 18, + "line": 16, "parameters": [ { "name": "x", @@ -137,7 +137,7 @@ "text": "number", "kind": "Primitive" }, - "line": 18 + "line": 16 }, { "name": "y", @@ -145,7 +145,7 @@ "text": "number", "kind": "Primitive" }, - "line": 18 + "line": 16 } ] } @@ -165,4 +165,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/extends-clause/test.ts b/tests/class/extends-clause/test.ts index 315fa216..6b62b8df 100644 --- a/tests/class/extends-clause/test.ts +++ b/tests/class/extends-clause/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { describe, expect } from 'vitest'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; const category = 'class'; const subcategory = 'extends-clause'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/implements-clause/output.json b/tests/class/implements-clause/output.json index b43d16ce..8e3a84f1 100644 --- a/tests/class/implements-clause/output.json +++ b/tests/class/implements-clause/output.json @@ -70,7 +70,7 @@ "kind": "Primitive" } }, - "line": 7, + "line": 6, "parameters": [ { "name": "x", @@ -78,7 +78,7 @@ "text": "number", "kind": "Primitive" }, - "line": 7 + "line": 6 }, { "name": "y", @@ -86,7 +86,7 @@ "text": "number", "kind": "Primitive" }, - "line": 7 + "line": 6 } ] } @@ -106,4 +106,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/implements-clause/test.ts b/tests/class/implements-clause/test.ts index 154a2627..2387156b 100644 --- a/tests/class/implements-clause/test.ts +++ b/tests/class/implements-clause/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'implements-clause'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/inheritance/output.json b/tests/class/inheritance/output.json index 4e1d3abc..1bb37422 100644 --- a/tests/class/inheritance/output.json +++ b/tests/class/inheritance/output.json @@ -152,7 +152,7 @@ "text": "number", "kind": "Primitive" }, - "line": 17, + "line": 16, "default": 5, "override": true }, @@ -180,7 +180,7 @@ "kind": "Primitive" } }, - "line": 19, + "line": 18, "parameters": [ { "name": "x", @@ -188,7 +188,7 @@ "text": "number", "kind": "Primitive" }, - "line": 19 + "line": 18 } ] } @@ -213,4 +213,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/inheritance/test.ts b/tests/class/inheritance/test.ts index f5728888..676e60c8 100644 --- a/tests/class/inheritance/test.ts +++ b/tests/class/inheritance/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'inheritance'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/initializers/output.json b/tests/class/initializers/output.json index f31fd045..5e14b983 100644 --- a/tests/class/initializers/output.json +++ b/tests/class/initializers/output.json @@ -20,7 +20,7 @@ } } }, - "line": 19 + "line": 18 } ], "properties": [ @@ -31,7 +31,7 @@ "text": "string", "kind": "Primitive" }, - "line": 9, + "line": 8, "readOnly": true }, { @@ -41,7 +41,7 @@ "text": "string", "kind": "Primitive" }, - "line": 11, + "line": 10, "default": "'foo'" }, { @@ -51,7 +51,7 @@ "text": "number", "kind": "Primitive" }, - "line": 13, + "line": 12, "default": 3 }, { @@ -61,7 +61,7 @@ "text": "number", "kind": "Primitive" }, - "line": 15, + "line": 14, "default": 3 }, { @@ -71,7 +71,7 @@ "text": "(x: number, y: number) => number", "kind": "Unknown" }, - "line": 17, + "line": 16, "default": "add" } ] @@ -84,4 +84,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/initializers/test.ts b/tests/class/initializers/test.ts index fbe959c5..0d01a19b 100644 --- a/tests/class/initializers/test.ts +++ b/tests/class/initializers/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'initializers'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/method-overload/output.json b/tests/class/method-overload/output.json index a42537be..0535a765 100644 --- a/tests/class/method-overload/output.json +++ b/tests/class/method-overload/output.json @@ -20,7 +20,7 @@ "kind": "Primitive" } }, - "line": 3, + "line": 2, "parameters": [ { "name": "a", @@ -28,7 +28,7 @@ "text": "string", "kind": "Primitive" }, - "line": 3 + "line": 2 }, { "name": "b", @@ -36,7 +36,7 @@ "text": "string", "kind": "Primitive" }, - "line": 3 + "line": 2 } ] }, @@ -47,7 +47,7 @@ "kind": "Primitive" } }, - "line": 4, + "line": 3, "parameters": [ { "name": "a", @@ -55,7 +55,7 @@ "text": "number", "kind": "Primitive" }, - "line": 4 + "line": 3 }, { "name": "b", @@ -63,7 +63,7 @@ "text": "number", "kind": "Primitive" }, - "line": 4 + "line": 3 } ] } @@ -79,4 +79,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/method-overload/test.ts b/tests/class/method-overload/test.ts index b25d60f4..b3cd2f28 100644 --- a/tests/class/method-overload/test.ts +++ b/tests/class/method-overload/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'method-overload'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/property-accessors/output.json b/tests/class/property-accessors/output.json index fb6a7d06..8070d842 100644 --- a/tests/class/property-accessors/output.json +++ b/tests/class/property-accessors/output.json @@ -16,7 +16,7 @@ "text": "string", "kind": "Primitive" }, - "line": 3, + "line": 2, "default": "'Foo'" }, { @@ -26,7 +26,7 @@ "text": "string", "kind": "Primitive" }, - "line": 13, + "line": 12, "default": "''" }, { @@ -36,7 +36,7 @@ "text": "number", "kind": "Primitive" }, - "line": 21, + "line": 20, "writeOnly": true } ], @@ -48,7 +48,7 @@ "text": "string", "kind": "Primitive" }, - "line": 5, + "line": 4, "default": "'Hello World'", "static": true, "readOnly": true @@ -66,7 +66,7 @@ "kind": "Primitive" } }, - "line": 25 + "line": 24 } ] } @@ -80,4 +80,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/property-accessors/test.ts b/tests/class/property-accessors/test.ts index dc11bbac..1c34e7b9 100644 --- a/tests/class/property-accessors/test.ts +++ b/tests/class/property-accessors/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'property-accessors'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/third-party-inheritance/output.json b/tests/class/third-party-inheritance/output.json index f8a2a28a..a5baf1af 100644 --- a/tests/class/third-party-inheritance/output.json +++ b/tests/class/third-party-inheritance/output.json @@ -23,7 +23,7 @@ "text": "number", "kind": "Primitive" }, - "line": 3, + "line": 2, "default": 3 } ] @@ -31,7 +31,7 @@ { "name": "BarElement", "kind": "Class", - "line": 7, + "line": 5, "heritage": [ { "name": "FooElement", @@ -51,7 +51,7 @@ "text": "number", "kind": "Primitive" }, - "line": 9, + "line": 6, "default": 4 }, { @@ -61,7 +61,7 @@ "text": "number", "kind": "Primitive" }, - "line": 3, + "line": 2, "default": 3, "inherited": true } @@ -79,4 +79,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/third-party-inheritance/test.ts b/tests/class/third-party-inheritance/test.ts index a3d29ca1..defda375 100644 --- a/tests/class/third-party-inheritance/test.ts +++ b/tests/class/third-party-inheritance/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'third-party-inheritance'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/class/typed-parameters-and-inheritance/output.json b/tests/class/typed-parameters-and-inheritance/output.json index 7ecb2c1c..ce80c652 100644 --- a/tests/class/typed-parameters-and-inheritance/output.json +++ b/tests/class/typed-parameters-and-inheritance/output.json @@ -328,4 +328,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/class/typed-parameters-and-inheritance/test.ts b/tests/class/typed-parameters-and-inheritance/test.ts index 8396a427..c8205697 100644 --- a/tests/class/typed-parameters-and-inheritance/test.ts +++ b/tests/class/typed-parameters-and-inheritance/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'class'; const subcategory = 'typed-parameters-and-inheritance'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/decorator/accessor/output.json b/tests/decorator/accessor/output.json index 97b91221..87b61314 100644 --- a/tests/decorator/accessor/output.json +++ b/tests/decorator/accessor/output.json @@ -11,8 +11,8 @@ { "return": { "type": { - "kind": "Unknown", - "text": "(_target: Point, _propertyKey: string, descriptor: PropertyDescriptor) => void" + "text": "(_target: Point, _propertyKey: string, descriptor: PropertyDescriptor) => void", + "kind": "Unknown" } }, "line": 1, @@ -45,7 +45,7 @@ } } }, - "line": 23, + "line": 22, "parameters": [ { "name": "x", @@ -53,7 +53,7 @@ "text": "number", "kind": "Primitive" }, - "line": 23 + "line": 22 }, { "name": "y", @@ -61,7 +61,7 @@ "text": "number", "kind": "Primitive" }, - "line": 23 + "line": 22 } ] } @@ -74,7 +74,7 @@ "text": "number", "kind": "Primitive" }, - "line": 9, + "line": 8, "decorators": [ { "name": "configurable", @@ -82,7 +82,9 @@ "path": "tests/decorator/accessor/index.ts", "line": 1 }, - "arguments": [false] + "arguments": [ + false + ] } ], "readOnly": true @@ -94,7 +96,7 @@ "text": "number", "kind": "Primitive" }, - "line": 14, + "line": 13, "decorators": [ { "name": "configurable", @@ -102,7 +104,9 @@ "path": "tests/decorator/accessor/index.ts", "line": 1 }, - "arguments": [false] + "arguments": [ + false + ] } ], "readOnly": true @@ -121,4 +125,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/decorator/accessor/test.ts b/tests/decorator/accessor/test.ts index 8b54552b..499bc3bb 100644 --- a/tests/decorator/accessor/test.ts +++ b/tests/decorator/accessor/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, updateExpectedOutput, test } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'decorator'; const subcategory = 'accessor'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/decorator/class/output.json b/tests/decorator/class/output.json index 62db9fcd..5a342412 100644 --- a/tests/decorator/class/output.json +++ b/tests/decorator/class/output.json @@ -20,8 +20,8 @@ { "name": "constructor", "type": { - "kind": "Unknown", - "text": "typeof BugReport" + "text": "typeof BugReport", + "kind": "Unknown" }, "line": 1 } @@ -45,7 +45,7 @@ } } }, - "line": 13, + "line": 12, "parameters": [ { "name": "t", @@ -53,7 +53,7 @@ "text": "string", "kind": "Primitive" }, - "line": 13 + "line": 12 } ] } @@ -75,7 +75,7 @@ "text": "string", "kind": "Primitive" }, - "line": 9, + "line": 8, "default": "'report'" }, { @@ -85,7 +85,7 @@ "text": "string", "kind": "Primitive" }, - "line": 11 + "line": 10 } ] } @@ -101,4 +101,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/decorator/class/test.ts b/tests/decorator/class/test.ts index 5c7001e4..d43c6eb8 100644 --- a/tests/decorator/class/test.ts +++ b/tests/decorator/class/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'decorator'; const subcategory = 'class'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/decorator/method/output.json b/tests/decorator/method/output.json index 0b6d54a5..a63ed3c7 100644 --- a/tests/decorator/method/output.json +++ b/tests/decorator/method/output.json @@ -11,8 +11,8 @@ { "return": { "type": { - "kind": "Unknown", - "text": "(_target: Greeter, _propertyKey: string, descriptor: PropertyDescriptor) => void" + "text": "(_target: Greeter, _propertyKey: string, descriptor: PropertyDescriptor) => void", + "kind": "Unknown" } }, "line": 1, @@ -45,7 +45,7 @@ } } }, - "line": 11, + "line": 10, "parameters": [ { "name": "message", @@ -53,7 +53,7 @@ "text": "string", "kind": "Primitive" }, - "line": 11 + "line": 10 } ] } @@ -66,7 +66,7 @@ "text": "string", "kind": "Primitive" }, - "line": 9 + "line": 8 } ], "methods": [ @@ -81,7 +81,7 @@ "kind": "Primitive" } }, - "line": 15 + "line": 14 } ], "decorators": [ @@ -91,7 +91,9 @@ "path": "tests/decorator/method/index.ts", "line": 1 }, - "arguments": [false] + "arguments": [ + false + ] } ] } @@ -109,4 +111,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/decorator/method/test.ts b/tests/decorator/method/test.ts index a7410539..53136299 100644 --- a/tests/decorator/method/test.ts +++ b/tests/decorator/method/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'decorator'; const subcategory = 'method'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/decorator/parameter/output.json b/tests/decorator/parameter/output.json index 832a9e58..dde41462 100644 --- a/tests/decorator/parameter/output.json +++ b/tests/decorator/parameter/output.json @@ -20,7 +20,7 @@ "kind": "Primitive" } }, - "line": 7, + "line": 6, "parameters": [ { "name": "name", @@ -28,7 +28,7 @@ "text": "string", "kind": "Primitive" }, - "line": 7, + "line": 6, "decorators": [ { "name": "log", @@ -53,4 +53,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/decorator/parameter/test.ts b/tests/decorator/parameter/test.ts index 5a5ad39e..44b82f4f 100644 --- a/tests/decorator/parameter/test.ts +++ b/tests/decorator/parameter/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'decorator'; const subcategory = 'parameter'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/decorator/property/output.json b/tests/decorator/property/output.json index 9eebec1c..3212528c 100644 --- a/tests/decorator/property/output.json +++ b/tests/decorator/property/output.json @@ -20,7 +20,7 @@ } } }, - "line": 29, + "line": 28, "parameters": [ { "name": "username", @@ -28,7 +28,7 @@ "text": "string", "kind": "Primitive" }, - "line": 29 + "line": 28 }, { "name": "password", @@ -36,7 +36,7 @@ "text": "string", "kind": "Primitive" }, - "line": 29 + "line": 28 } ] } @@ -49,7 +49,7 @@ "text": "string", "kind": "Primitive" }, - "line": 24 + "line": 23 }, { "name": "password", @@ -58,7 +58,7 @@ "text": "string", "kind": "Primitive" }, - "line": 26, + "line": 25, "decorators": [ { "name": "min", @@ -66,7 +66,9 @@ "path": "tests/decorator/property/index.ts", "line": 1 }, - "arguments": [8] + "arguments": [ + 8 + ] } ] } @@ -80,4 +82,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/decorator/property/test.ts b/tests/decorator/property/test.ts index 332d4ba7..f8aef3ab 100644 --- a/tests/decorator/property/test.ts +++ b/tests/decorator/property/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'decorator'; const subcategory = 'property'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/enum/basic/output.json b/tests/enum/basic/output.json index 1e9455bc..469c9c17 100644 --- a/tests/enum/basic/output.json +++ b/tests/enum/basic/output.json @@ -35,4 +35,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/enum/basic/test.ts b/tests/enum/basic/test.ts index 587936fd..d43a64ad 100644 --- a/tests/enum/basic/test.ts +++ b/tests/enum/basic/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'enum'; const subcategory = 'basic'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/enum/initializers/output.json b/tests/enum/initializers/output.json index 39152b0a..58e97268 100644 --- a/tests/enum/initializers/output.json +++ b/tests/enum/initializers/output.json @@ -43,4 +43,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/enum/initializers/test.ts b/tests/enum/initializers/test.ts index f3dbbad9..4e491526 100644 --- a/tests/enum/initializers/test.ts +++ b/tests/enum/initializers/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'enum'; const subcategory = 'initializers'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/export/default/output.json b/tests/export/default/output.json index bea043d6..fbb93c2f 100644 --- a/tests/export/default/output.json +++ b/tests/export/default/output.json @@ -22,4 +22,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/export/default/test.ts b/tests/export/default/test.ts index fd98c520..87ff22fa 100644 --- a/tests/export/default/test.ts +++ b/tests/export/default/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'export'; const subcategory = 'default'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/export/named/output.json b/tests/export/named/output.json index 32491beb..bfc9dc22 100644 --- a/tests/export/named/output.json +++ b/tests/export/named/output.json @@ -69,4 +69,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/export/named/test.ts b/tests/export/named/test.ts index 891e019f..6cf2c86f 100644 --- a/tests/export/named/test.ts +++ b/tests/export/named/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'export'; const subcategory = 'named'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/export/namespace/output.json b/tests/export/namespace/output.json index bfc59668..e24246f2 100644 --- a/tests/export/namespace/output.json +++ b/tests/export/namespace/output.json @@ -35,4 +35,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/export/namespace/test.ts b/tests/export/namespace/test.ts index dc6bdedf..b4648dbf 100644 --- a/tests/export/namespace/test.ts +++ b/tests/export/namespace/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'export'; const subcategory = 'namespace'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/export/renamed/output.json b/tests/export/renamed/output.json index fe4514a1..c0da1473 100644 --- a/tests/export/renamed/output.json +++ b/tests/export/renamed/output.json @@ -23,4 +23,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/export/renamed/test.ts b/tests/export/renamed/test.ts index c3c620c8..3dc824f0 100644 --- a/tests/export/renamed/test.ts +++ b/tests/export/renamed/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'export'; const subcategory = 'renamed'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/export/star/output.json b/tests/export/star/output.json index 50bce8ce..49634681 100644 --- a/tests/export/star/output.json +++ b/tests/export/star/output.json @@ -63,4 +63,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/export/star/test.ts b/tests/export/star/test.ts index df089530..86332856 100644 --- a/tests/export/star/test.ts +++ b/tests/export/star/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'export'; const subcategory = 'star'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/export/type/output.json b/tests/export/type/output.json index b50b0f9b..41f32eed 100644 --- a/tests/export/type/output.json +++ b/tests/export/type/output.json @@ -16,7 +16,7 @@ "text": "number", "kind": "Primitive" }, - "line": 3, + "line": 2, "default": 4 } ] @@ -65,4 +65,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/export/type/test.ts b/tests/export/type/test.ts index 28c80735..e62a4612 100644 --- a/tests/export/type/test.ts +++ b/tests/export/type/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'export'; const subcategory = 'type'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/from-glob/output.json b/tests/from-glob/output.json index aadafa9c..8179f8a9 100644 --- a/tests/from-glob/output.json +++ b/tests/from-glob/output.json @@ -5,12 +5,12 @@ "imports": [], "declarations": [ { - "kind": "Variable", "name": "foo", + "kind": "Variable", "line": 1, "type": { - "kind": "Primitive", - "text": "boolean" + "text": "boolean", + "kind": "Primitive" }, "default": true } @@ -22,4 +22,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/from-glob/test.ts b/tests/from-glob/test.ts index 9215f96d..0e2472a6 100644 --- a/tests/from-glob/test.ts +++ b/tests/from-glob/test.ts @@ -1,6 +1,6 @@ +import { readExpectedOutput, test, updateExpectedOutput } from '../utils.js'; import { parseFromGlob } from '@ts-ast-parser/core'; -import { readExpectedOutput } from '../utils.js'; -import { describe, expect, it } from 'vitest'; +import { describe, expect } from 'vitest'; import path from 'path'; const category = 'from-glob'; @@ -8,8 +8,14 @@ const expected = readExpectedOutput(category); const actual = await parseFromGlob(path.join(process.cwd(), 'tests', category, 'index.ts')); describe(category, () => { - it('should reflect the expected modules', () => { - const result = actual.result?.map(m => m.serialize()); + test('should reflect the expected modules', ({ update }) => { + const result = actual.result?.map(m => m.serialize()) ?? []; + + if (update) { + updateExpectedOutput(result, category); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/from-project/basic/output.json b/tests/from-project/basic/output.json index 41543ec8..75794d2c 100644 --- a/tests/from-project/basic/output.json +++ b/tests/from-project/basic/output.json @@ -161,4 +161,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/from-project/basic/test.ts b/tests/from-project/basic/test.ts index f42c1f75..aa3d2897 100644 --- a/tests/from-project/basic/test.ts +++ b/tests/from-project/basic/test.ts @@ -1,6 +1,6 @@ +import { readExpectedOutput, test, updateExpectedOutput } from '../../utils.js'; import { parseFromProject } from '@ts-ast-parser/core'; -import { readExpectedOutput } from '../../utils.js'; -import { describe, expect, it } from 'vitest'; +import { describe, expect } from 'vitest'; import * as path from 'path'; const category = 'from-project'; @@ -11,8 +11,14 @@ const actual = await parseFromProject({ }); describe(category, () => { - it('should reflect the expected modules', () => { - const result = actual?.result?.getModules().map(m => m.serialize()); + test('should reflect the expected modules', ({ update }) => { + const result = actual?.result?.getModules().map(m => m.serialize()) ?? []; + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); expect(actual?.result?.getName()).to.equal('test-project'); }); diff --git a/tests/from-project/monorepo/test-project/packages/a/output.json b/tests/from-project/monorepo/test-project/packages/a/output.json index be207f00..7926a284 100644 --- a/tests/from-project/monorepo/test-project/packages/a/output.json +++ b/tests/from-project/monorepo/test-project/packages/a/output.json @@ -70,4 +70,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/from-project/monorepo/test-project/packages/b/output.json b/tests/from-project/monorepo/test-project/packages/b/output.json index ad1b457d..64e64215 100644 --- a/tests/from-project/monorepo/test-project/packages/b/output.json +++ b/tests/from-project/monorepo/test-project/packages/b/output.json @@ -14,7 +14,7 @@ { "name": "Employee", "kind": "Class", - "line": 4, + "line": 3, "constructors": [ { "return": { @@ -22,12 +22,12 @@ "text": "Employee", "kind": "Reference", "source": { - "line": 4, + "line": 3, "path": "tests/from-project/monorepo/test-project/packages/b/src/index.ts" } } }, - "line": 7, + "line": 6, "parameters": [ { "name": "name", @@ -35,7 +35,7 @@ "text": "string", "kind": "Primitive" }, - "line": 7 + "line": 6 }, { "name": "age", @@ -43,7 +43,7 @@ "text": "number", "kind": "Primitive" }, - "line": 7 + "line": 6 }, { "name": "salary", @@ -51,7 +51,7 @@ "text": "number", "kind": "Primitive" }, - "line": 7 + "line": 6 } ] } @@ -74,7 +74,7 @@ "text": "number", "kind": "Primitive" }, - "line": 5 + "line": 4 }, { "name": "name", @@ -106,4 +106,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/from-project/monorepo/test.ts b/tests/from-project/monorepo/test.ts index b0e60223..db268a49 100644 --- a/tests/from-project/monorepo/test.ts +++ b/tests/from-project/monorepo/test.ts @@ -1,5 +1,6 @@ import { parseFromProject } from '@ts-ast-parser/core'; -import { describe, expect, it } from 'vitest'; +import { describe, expect } from 'vitest'; +import { test } from '../../utils.js'; import * as path from 'path'; import * as fs from 'fs'; @@ -11,10 +12,15 @@ const pkgs = fs.readdirSync(pkgsDir); describe(category, () => { for (const pkg of pkgs) { - it(`should reflect the expected modules of package @test-project/${pkg}`, async () => { + test(`should reflect the expected modules of package @test-project/${pkg}`, async ({ update }) => { const expected = JSON.parse(fs.readFileSync(path.join(pkgsDir, pkg, 'output.json'), 'utf-8')); const actual = await parseFromProject({ tsConfigFilePath: path.join(pkgsDir, pkg, 'tsconfig.json') }); - const result = actual?.result?.getModules().map(m => m.serialize()); + const result = actual?.result?.getModules().map(m => m.serialize()) ?? []; + + if (update) { + fs.writeFileSync(path.join(pkgsDir, pkg, 'output.json'), JSON.stringify(result, null, 4)); + return; + } expect(result).to.deep.equal(expected); expect(actual?.result?.getName()).to.equal(`@test-project/${pkg}`); diff --git a/tests/from-source/output.json b/tests/from-source/output.json index dcdb0790..07c8ca32 100644 --- a/tests/from-source/output.json +++ b/tests/from-source/output.json @@ -20,4 +20,4 @@ "kind": "Named" } ] -} +} \ No newline at end of file diff --git a/tests/from-source/test.ts b/tests/from-source/test.ts index e939f238..981408b4 100644 --- a/tests/from-source/test.ts +++ b/tests/from-source/test.ts @@ -1,13 +1,20 @@ -import { parseFromSource } from '@ts-ast-parser/core'; -import { readExpectedOutput } from '../utils.js'; -import { describe, expect, it } from 'vitest'; +import { readExpectedOutput, test, updateExpectedOutput } from '../utils.js'; +import { type Module, parseFromSource } from '@ts-ast-parser/core'; +import { describe, expect } from 'vitest'; const category = 'from-source'; const expected = readExpectedOutput(category); const actual = await parseFromSource('const foo = true;export { foo };'); describe(category, () => { - it('should reflect the expected modules', () => { - expect(actual?.result?.serialize()).to.deep.equal(expected); + test('should reflect the expected modules', ({ update }) => { + const result = actual?.result?.serialize() ?? ({} as Module); + + if (update) { + updateExpectedOutput(result, category); + return; + } + + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/function/anonymous/output.json b/tests/function/anonymous/output.json index b2c89a7a..fcc3f370 100644 --- a/tests/function/anonymous/output.json +++ b/tests/function/anonymous/output.json @@ -161,4 +161,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/function/anonymous/test.ts b/tests/function/anonymous/test.ts index 55db9a10..9ac36b4c 100644 --- a/tests/function/anonymous/test.ts +++ b/tests/function/anonymous/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'function'; const subcategory = 'anonymous'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/function/arrow/output.json b/tests/function/arrow/output.json index dfc17003..fec85cc8 100644 --- a/tests/function/arrow/output.json +++ b/tests/function/arrow/output.json @@ -59,4 +59,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/function/arrow/test.ts b/tests/function/arrow/test.ts index 31600944..dd88ac0e 100644 --- a/tests/function/arrow/test.ts +++ b/tests/function/arrow/test.ts @@ -1,13 +1,19 @@ -import { getTestResult } from '../../utils.js'; -import { describe, expect, it } from 'vitest'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'function'; const subcategory = 'arrow'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/function/async/output.json b/tests/function/async/output.json index 22fa322a..5b755363 100644 --- a/tests/function/async/output.json +++ b/tests/function/async/output.json @@ -46,4 +46,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/function/async/test.ts b/tests/function/async/test.ts index ff456d80..23bcd227 100644 --- a/tests/function/async/test.ts +++ b/tests/function/async/test.ts @@ -1,13 +1,19 @@ -import { getTestResult } from '../../utils.js'; -import { describe, expect, it } from 'vitest'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'function'; const subcategory = 'async'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/function/basic/output.json b/tests/function/basic/output.json index d98754fa..2d2ad463 100644 --- a/tests/function/basic/output.json +++ b/tests/function/basic/output.json @@ -59,4 +59,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/function/basic/test.ts b/tests/function/basic/test.ts index bc27e096..da8069a6 100644 --- a/tests/function/basic/test.ts +++ b/tests/function/basic/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'function'; const subcategory = 'basic'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/function/const-type-parameters/output.json b/tests/function/const-type-parameters/output.json index 52f3e935..c278de12 100644 --- a/tests/function/const-type-parameters/output.json +++ b/tests/function/const-type-parameters/output.json @@ -142,7 +142,7 @@ ] } }, - "default": "getNamesExactly({names: ['Alice', 'Bob', 'Eve']})" + "default": "getNamesExactly({ names: ['Alice', 'Bob', 'Eve'] })" } ], "exports": [ @@ -164,4 +164,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/function/const-type-parameters/test.ts b/tests/function/const-type-parameters/test.ts index 18c8473e..1cc3d359 100644 --- a/tests/function/const-type-parameters/test.ts +++ b/tests/function/const-type-parameters/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'function'; const subcategory = 'const-type-parameters'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/function/generator/output.json b/tests/function/generator/output.json index ead37606..b6d20ee5 100644 --- a/tests/function/generator/output.json +++ b/tests/function/generator/output.json @@ -42,4 +42,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/function/generator/test.ts b/tests/function/generator/test.ts index aa8f062f..208aba3d 100644 --- a/tests/function/generator/test.ts +++ b/tests/function/generator/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'function'; const subcategory = 'generator'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/function/named-parameters/output.json b/tests/function/named-parameters/output.json index 0f689e08..05e5a335 100644 --- a/tests/function/named-parameters/output.json +++ b/tests/function/named-parameters/output.json @@ -58,4 +58,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/function/named-parameters/test.ts b/tests/function/named-parameters/test.ts index 74836a2d..8ad3ad7b 100644 --- a/tests/function/named-parameters/test.ts +++ b/tests/function/named-parameters/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'function'; const subcategory = 'named-parameters'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/function/overload/output.json b/tests/function/overload/output.json index dae251a5..5080f638 100644 --- a/tests/function/overload/output.json +++ b/tests/function/overload/output.json @@ -72,4 +72,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/function/overload/test.ts b/tests/function/overload/test.ts index 20f2976a..99ef2891 100644 --- a/tests/function/overload/test.ts +++ b/tests/function/overload/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'function'; const subcategory = 'overload'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/import/default/output.json b/tests/import/default/output.json index 663ca61c..40e36f1f 100644 --- a/tests/import/default/output.json +++ b/tests/import/default/output.json @@ -27,7 +27,7 @@ "kind": "Primitive" } }, - "line": 3 + "line": 2 } ] } @@ -54,4 +54,4 @@ "declarations": [], "exports": [] } -] +] \ No newline at end of file diff --git a/tests/import/default/test.ts b/tests/import/default/test.ts index 81840578..5005923a 100644 --- a/tests/import/default/test.ts +++ b/tests/import/default/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'import'; const subcategory = 'default'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/import/multiple/output.json b/tests/import/multiple/output.json index b96d32be..7aa97241 100644 --- a/tests/import/multiple/output.json +++ b/tests/import/multiple/output.json @@ -20,7 +20,7 @@ "kind": "Primitive" } }, - "line": 3, + "line": 2, "parameters": [ { "name": "x", @@ -28,7 +28,7 @@ "text": "number", "kind": "Primitive" }, - "line": 3 + "line": 2 } ] } @@ -39,7 +39,7 @@ { "name": "bar", "kind": "Variable", - "line": 11, + "line": 9, "type": { "text": "number", "kind": "Primitive" @@ -76,4 +76,4 @@ "declarations": [], "exports": [] } -] +] \ No newline at end of file diff --git a/tests/import/multiple/test.ts b/tests/import/multiple/test.ts index 1a441d24..f56c604a 100644 --- a/tests/import/multiple/test.ts +++ b/tests/import/multiple/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'import'; const subcategory = 'multiple'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/import/named/output.json b/tests/import/named/output.json index eb7a304a..57bac1db 100644 --- a/tests/import/named/output.json +++ b/tests/import/named/output.json @@ -20,7 +20,7 @@ "kind": "Primitive" } }, - "line": 3 + "line": 2 } ] } @@ -47,4 +47,4 @@ "declarations": [], "exports": [] } -] +] \ No newline at end of file diff --git a/tests/import/named/test.ts b/tests/import/named/test.ts index 663f71b5..7cc8bd50 100644 --- a/tests/import/named/test.ts +++ b/tests/import/named/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'import'; const subcategory = 'named'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/import/namespace/output.json b/tests/import/namespace/output.json index 3aa3a8e4..77475c7a 100644 --- a/tests/import/namespace/output.json +++ b/tests/import/namespace/output.json @@ -30,7 +30,7 @@ "kind": "Primitive" } }, - "line": 5 + "line": 4 } ] } @@ -61,4 +61,4 @@ "declarations": [], "exports": [] } -] +] \ No newline at end of file diff --git a/tests/import/namespace/test.ts b/tests/import/namespace/test.ts index 461846dc..398cfa7e 100644 --- a/tests/import/namespace/test.ts +++ b/tests/import/namespace/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'import'; const subcategory = 'namespace'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/import/paths/index.ts b/tests/import/paths/index.ts index 06b3310c..58343699 100644 --- a/tests/import/paths/index.ts +++ b/tests/import/paths/index.ts @@ -1,4 +1,5 @@ -// @ts-expect-error The path will be provided in the compiler options +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore The path will be provided in the compiler options import { Foo } from 'custom-path/foo'; export class Bar extends Foo { diff --git a/tests/import/paths/output.json b/tests/import/paths/output.json index 5a55b673..e6edecbe 100644 --- a/tests/import/paths/output.json +++ b/tests/import/paths/output.json @@ -45,7 +45,7 @@ { "name": "Bar", "kind": "Class", - "line": 7, + "line": 5, "heritage": [ { "name": "Foo", @@ -64,7 +64,7 @@ "text": "number", "kind": "Primitive" }, - "line": 8, + "line": 6, "default": 4 } ] @@ -77,4 +77,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/import/paths/test.ts b/tests/import/paths/test.ts index d49e0e11..cf07130a 100644 --- a/tests/import/paths/test.ts +++ b/tests/import/paths/test.ts @@ -1,5 +1,5 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; import * as path from 'path'; const category = 'import'; @@ -17,8 +17,14 @@ const compilerOptions = { const { actual, expected } = await getTestResult({ category, subcategory, analyzerOptions: { compilerOptions } }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/import/side-effect/output.json b/tests/import/side-effect/output.json index ca4e08f1..83ed330a 100644 --- a/tests/import/side-effect/output.json +++ b/tests/import/side-effect/output.json @@ -41,4 +41,4 @@ "declarations": [], "exports": [] } -] +] \ No newline at end of file diff --git a/tests/import/side-effect/test.ts b/tests/import/side-effect/test.ts index c825ab0a..bcab9cc1 100644 --- a/tests/import/side-effect/test.ts +++ b/tests/import/side-effect/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'import'; const subcategory = 'side-effect'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/import/type/output.json b/tests/import/type/output.json index c0ce5ff4..5cf2e1e2 100644 --- a/tests/import/type/output.json +++ b/tests/import/type/output.json @@ -14,7 +14,7 @@ { "name": "x", "kind": "Variable", - "line": 4, + "line": 3, "type": { "text": "TypeA", "kind": "Reference", @@ -23,7 +23,7 @@ "path": "tests/import/type/type-a.ts" } }, - "default": "{foo: 'bar'}" + "default": "{ foo: 'bar' }" } ], "exports": [ @@ -63,4 +63,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/import/type/test.ts b/tests/import/type/test.ts index f2e2e3ee..09232ddd 100644 --- a/tests/import/type/test.ts +++ b/tests/import/type/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'import'; const subcategory = 'type'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/interface/accessors/output.json b/tests/interface/accessors/output.json index 18a6be6f..b4d59b68 100644 --- a/tests/interface/accessors/output.json +++ b/tests/interface/accessors/output.json @@ -16,7 +16,7 @@ "text": "string", "kind": "Primitive" }, - "line": 3 + "line": 2 }, { "name": "baz", @@ -25,7 +25,7 @@ "text": "string", "kind": "Primitive" }, - "line": 6, + "line": 5, "readOnly": true }, { @@ -35,7 +35,7 @@ "text": "string", "kind": "Primitive" }, - "line": 8, + "line": 7, "writeOnly": true } ] @@ -48,4 +48,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/interface/accessors/test.ts b/tests/interface/accessors/test.ts index d62a3f9a..8caebb16 100644 --- a/tests/interface/accessors/test.ts +++ b/tests/interface/accessors/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'interface'; const subcategory = 'accessors'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/interface/basic/output.json b/tests/interface/basic/output.json index e9601c4a..54aa522d 100644 --- a/tests/interface/basic/output.json +++ b/tests/interface/basic/output.json @@ -214,4 +214,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/interface/basic/test.ts b/tests/interface/basic/test.ts index ec6efba3..54d678fc 100644 --- a/tests/interface/basic/test.ts +++ b/tests/interface/basic/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'interface'; const subcategory = 'basic'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/interface/index-signature/output.json b/tests/interface/index-signature/output.json index 2fb7091d..d0c7f0f4 100644 --- a/tests/interface/index-signature/output.json +++ b/tests/interface/index-signature/output.json @@ -82,4 +82,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/interface/index-signature/test.ts b/tests/interface/index-signature/test.ts index 3c325832..69932a63 100644 --- a/tests/interface/index-signature/test.ts +++ b/tests/interface/index-signature/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'interface'; const subcategory = 'index-signature'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/interface/method-overload/output.json b/tests/interface/method-overload/output.json index 40c172dc..172f89aa 100644 --- a/tests/interface/method-overload/output.json +++ b/tests/interface/method-overload/output.json @@ -106,4 +106,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/interface/method-overload/test.ts b/tests/interface/method-overload/test.ts index e63c175a..ad58704b 100644 --- a/tests/interface/method-overload/test.ts +++ b/tests/interface/method-overload/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'interface'; const subcategory = 'method-overload'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/interface/typed-parameters-and-inheritance/output.json b/tests/interface/typed-parameters-and-inheritance/output.json index ec1df70c..f972aa6f 100644 --- a/tests/interface/typed-parameters-and-inheritance/output.json +++ b/tests/interface/typed-parameters-and-inheritance/output.json @@ -157,4 +157,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/interface/typed-parameters-and-inheritance/test.ts b/tests/interface/typed-parameters-and-inheritance/test.ts index 955ba881..d730f98b 100644 --- a/tests/interface/typed-parameters-and-inheritance/test.ts +++ b/tests/interface/typed-parameters-and-inheritance/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'interface'; const subcategory = 'typed-parameters-and-inheritance'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/interface/utility-types/output.json b/tests/interface/utility-types/output.json index 5eb68350..e2b98069 100644 --- a/tests/interface/utility-types/output.json +++ b/tests/interface/utility-types/output.json @@ -96,4 +96,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/interface/utility-types/test.ts b/tests/interface/utility-types/test.ts index 88784578..9f503e03 100644 --- a/tests/interface/utility-types/test.ts +++ b/tests/interface/utility-types/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'interface'; const subcategory = 'utility-types'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/jsdoc/description/output.json b/tests/jsdoc/description/output.json index 81ab36e3..04687090 100644 --- a/tests/jsdoc/description/output.json +++ b/tests/jsdoc/description/output.json @@ -9,8 +9,8 @@ "kind": "Variable", "line": 12, "type": { - "kind": "Primitive", - "text": "number" + "text": "number", + "kind": "Primitive" }, "default": 4, "jsDoc": [ @@ -28,4 +28,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/jsdoc/description/test.ts b/tests/jsdoc/description/test.ts index b1fbfe82..0933b3d0 100644 --- a/tests/jsdoc/description/test.ts +++ b/tests/jsdoc/description/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'jsdoc'; const subcategory = 'description'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/jsdoc/ignore/output.json b/tests/jsdoc/ignore/output.json index 97f3bb65..0a3de22e 100644 --- a/tests/jsdoc/ignore/output.json +++ b/tests/jsdoc/ignore/output.json @@ -6,4 +6,4 @@ "declarations": [], "exports": [] } -] +] \ No newline at end of file diff --git a/tests/jsdoc/ignore/test.ts b/tests/jsdoc/ignore/test.ts index 51d376cb..f4c6fddc 100644 --- a/tests/jsdoc/ignore/test.ts +++ b/tests/jsdoc/ignore/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'jsdoc'; const subcategory = 'ignore'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/jsdoc/tags/output.json b/tests/jsdoc/tags/output.json index 01b0837e..fdb071b3 100644 --- a/tests/jsdoc/tags/output.json +++ b/tests/jsdoc/tags/output.json @@ -44,4 +44,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/jsdoc/tags/test.ts b/tests/jsdoc/tags/test.ts index 2cd22f74..389361a1 100644 --- a/tests/jsdoc/tags/test.ts +++ b/tests/jsdoc/tags/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'jsdoc'; const subcategory = 'tags'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/mixin/general-use-case/test.ts b/tests/mixin/general-use-case/test.ts index 6648f0a0..40323dfa 100644 --- a/tests/mixin/general-use-case/test.ts +++ b/tests/mixin/general-use-case/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'mixin'; const subcategory = 'general-use-case'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it.skip('should reflect the expected modules', () => { + test.skip('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/mixin/mixin-builder/test.ts b/tests/mixin/mixin-builder/test.ts index 4ae4944d..ffc5f19b 100644 --- a/tests/mixin/mixin-builder/test.ts +++ b/tests/mixin/mixin-builder/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'mixin'; const subcategory = 'mixin-builder'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it.skip('should reflect the expected modules', () => { + test.skip('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/namespace/basic/output.json b/tests/namespace/basic/output.json index 7407d0ab..319b07b7 100644 --- a/tests/namespace/basic/output.json +++ b/tests/namespace/basic/output.json @@ -7,7 +7,7 @@ { "name": "TypeFoo", "kind": "TypeAlias", - "line": 4, + "line": 3, "value": { "text": "{\n bar: number;\n }", "kind": "ObjectLiteral", @@ -19,7 +19,7 @@ "text": "number", "kind": "Primitive" }, - "line": 5 + "line": 4 } ] }, @@ -28,7 +28,7 @@ { "kind": "Enum", "name": "EnumFoo", - "line": 8, + "line": 7, "namespace": "Foo", "members": [ { @@ -52,7 +52,7 @@ { "name": "varFoo", "kind": "Variable", - "line": 15, + "line": 14, "type": { "text": "number", "kind": "Primitive" @@ -63,7 +63,7 @@ { "name": "IFoo", "kind": "Interface", - "line": 17, + "line": 16, "namespace": "Foo", "properties": [ { @@ -73,19 +73,19 @@ "text": "number", "kind": "Primitive" }, - "line": 18 + "line": 17 } ] }, { "name": "ClassFoo", "kind": "Class", - "line": 21, + "line": 20, "heritage": [ { "name": "IFoo", "source": { - "line": 17, + "line": 16, "path": "tests/namespace/basic/index.ts" }, "kind": "Interface" @@ -100,7 +100,7 @@ "text": "number", "kind": "Primitive" }, - "line": 22, + "line": 21, "default": 3 } ] @@ -116,7 +116,7 @@ "kind": "Primitive" } }, - "line": 25 + "line": 24 } ], "namespace": "Foo" @@ -149,4 +149,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/namespace/basic/test.ts b/tests/namespace/basic/test.ts index d6f48cb8..3e47d54b 100644 --- a/tests/namespace/basic/test.ts +++ b/tests/namespace/basic/test.ts @@ -1,13 +1,19 @@ -import { getTestResult } from '../../utils.js'; -import { describe, expect, it } from 'vitest'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'namespace'; const subcategory = 'basic'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/namespace/nested/output.json b/tests/namespace/nested/output.json index 63a8ed5d..f6a1e1ca 100644 --- a/tests/namespace/nested/output.json +++ b/tests/namespace/nested/output.json @@ -7,7 +7,7 @@ { "name": "BarType", "kind": "TypeAlias", - "line": 7, + "line": 5, "value": { "text": "string | number", "kind": "Union", @@ -32,4 +32,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/namespace/nested/test.ts b/tests/namespace/nested/test.ts index 30f2a917..c9117616 100644 --- a/tests/namespace/nested/test.ts +++ b/tests/namespace/nested/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'namespace'; const subcategory = 'nested'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/type-alias/basic/output.json b/tests/type-alias/basic/output.json index fbc8720b..1229d4c0 100644 --- a/tests/type-alias/basic/output.json +++ b/tests/type-alias/basic/output.json @@ -32,4 +32,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/type-alias/basic/test.ts b/tests/type-alias/basic/test.ts index f7dd3f13..05ac9861 100644 --- a/tests/type-alias/basic/test.ts +++ b/tests/type-alias/basic/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'type-alias'; const subcategory = 'basic'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/type-alias/type-parameters/output.json b/tests/type-alias/type-parameters/output.json index e5e09337..6f918e7c 100644 --- a/tests/type-alias/type-parameters/output.json +++ b/tests/type-alias/type-parameters/output.json @@ -63,4 +63,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/type-alias/type-parameters/test.ts b/tests/type-alias/type-parameters/test.ts index 9ec497b2..538e4e27 100644 --- a/tests/type-alias/type-parameters/test.ts +++ b/tests/type-alias/type-parameters/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'type-alias'; const subcategory = 'type-parameters'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/utils.ts b/tests/utils.ts index be9f130c..441b5d20 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -1,5 +1,6 @@ import type { AnalyserOptions, Module, ModuleNode } from '@ts-ast-parser/core'; import { parseFromFiles } from '@ts-ast-parser/core'; +import { test as base } from 'vitest'; import * as path from 'path'; import * as fs from 'fs'; @@ -11,6 +12,10 @@ type TestOptions = { const basedDir = path.join(process.cwd(), 'tests'); +export const test = base.extend<{ update: boolean }>({ + update: !!process.env['UPDATE_SNAPSHOTS'], +}); + export async function getTestResult(options: TestOptions): Promise<{ actual: ModuleNode[]; expected: Module[] }> { const { category, subcategory, analyzerOptions } = options; const expectedOutputFile = readExpectedOutput(category, subcategory); @@ -27,8 +32,8 @@ export async function getTestResult(options: TestOptions): Promise<{ actual: Mod }; } -export function readExpectedOutput(category: string, subcategory = '', fileName = 'output.json'): Module[] { - const expectedOutputPath = path.join(basedDir, category, subcategory, fileName); +export function readExpectedOutput(category: string, subcategory = ''): Module[] { + const expectedOutputPath = path.join(basedDir, category, subcategory, 'output.json'); if (!fs.existsSync(expectedOutputPath)) { return []; @@ -40,3 +45,7 @@ export function readExpectedOutput(category: string, subcategory = '', fileName return []; } } + +export function updateExpectedOutput(content: Module | Module[], category: string, subcategory = ''): void { + fs.writeFileSync(path.join(basedDir, category, subcategory, 'output.json'), JSON.stringify(content, null, 4)); +} diff --git a/tests/variable/basic/output.json b/tests/variable/basic/output.json index fdcf62c3..e06a69c3 100644 --- a/tests/variable/basic/output.json +++ b/tests/variable/basic/output.json @@ -5,12 +5,12 @@ "imports": [], "declarations": [ { + "name": "foo", "kind": "Variable", "line": 2, - "name": "foo", "type": { - "kind": "Primitive", - "text": "number" + "text": "number", + "kind": "Primitive" }, "default": "bar + 3" } @@ -22,4 +22,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/variable/basic/test.ts b/tests/variable/basic/test.ts index 9d83c5b0..9979ce03 100644 --- a/tests/variable/basic/test.ts +++ b/tests/variable/basic/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'variable'; const subcategory = 'basic'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/variable/complex-types/output.json b/tests/variable/complex-types/output.json index 97b43853..136d847b 100644 --- a/tests/variable/complex-types/output.json +++ b/tests/variable/complex-types/output.json @@ -9,26 +9,26 @@ "kind": "TypeAlias", "line": 8, "value": { - "text": "{x: number; y?: number}", + "text": "{ x: number; y?: number }", "kind": "ObjectLiteral", "properties": [ { "name": "x", - "line": 8, "kind": "Property", "type": { "text": "number", "kind": "Primitive" - } + }, + "line": 8 }, { "name": "y", - "line": 8, "kind": "Property", "type": { "text": "number", "kind": "Primitive" }, + "line": 8, "optional": true } ] @@ -39,17 +39,17 @@ "kind": "TypeAlias", "line": 9, "value": { - "text": "{z?: boolean}", + "text": "{ z?: boolean }", "kind": "ObjectLiteral", "properties": [ { "name": "z", - "line": 9, "kind": "Property", "type": { "text": "boolean", "kind": "Primitive" }, + "line": 9, "optional": true } ] @@ -112,7 +112,7 @@ "path": "tests/variable/complex-types/index.ts" } }, - "default": "{x: 4, y: 4}" + "default": "{ x: 4, y: 4 }" }, { "name": "bar2", @@ -140,7 +140,7 @@ } ] }, - "default": "{x: 3}" + "default": "{ x: 3 }" }, { "name": "foo2", @@ -214,4 +214,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/variable/complex-types/test.ts b/tests/variable/complex-types/test.ts index d2626980..124c427c 100644 --- a/tests/variable/complex-types/test.ts +++ b/tests/variable/complex-types/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'variable'; const subcategory = 'complex-types'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/variable/identifier-as-initializer/output.json b/tests/variable/identifier-as-initializer/output.json index 412072bf..412de267 100644 --- a/tests/variable/identifier-as-initializer/output.json +++ b/tests/variable/identifier-as-initializer/output.json @@ -76,13 +76,13 @@ "name": "x", "kind": "Property", "type": { - "kind": "Primitive", - "text": "number" + "text": "number", + "kind": "Primitive" } } ] }, - "default": "{x: 3}" + "default": "{ x: 3 }" }, { "name": "arr", @@ -134,4 +134,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/variable/identifier-as-initializer/test.ts b/tests/variable/identifier-as-initializer/test.ts index 0bced27f..fdb81224 100644 --- a/tests/variable/identifier-as-initializer/test.ts +++ b/tests/variable/identifier-as-initializer/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'variable'; const subcategory = 'identifier-as-initializer'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/variable/imported-initializer/output.json b/tests/variable/imported-initializer/output.json index 822d1464..337c14a0 100644 --- a/tests/variable/imported-initializer/output.json +++ b/tests/variable/imported-initializer/output.json @@ -36,7 +36,7 @@ { "name": "bar", "kind": "Variable", - "line": 4, + "line": 3, "type": { "text": "number", "kind": "Primitive" @@ -51,4 +51,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/variable/imported-initializer/test.ts b/tests/variable/imported-initializer/test.ts index 693c8751..05bbe8d0 100644 --- a/tests/variable/imported-initializer/test.ts +++ b/tests/variable/imported-initializer/test.ts @@ -1,13 +1,19 @@ -import { getTestResult } from '../../utils.js'; -import { describe, expect, it } from 'vitest'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'variable'; const subcategory = 'imported-initializer'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/variable/satisfies-operator/output.json b/tests/variable/satisfies-operator/output.json index 89461d0e..a94c52fa 100644 --- a/tests/variable/satisfies-operator/output.json +++ b/tests/variable/satisfies-operator/output.json @@ -36,19 +36,19 @@ "kind": "Tuple", "elements": [ { + "name": "red", "text": "number", - "kind": "Primitive", - "name": "red" + "kind": "Primitive" }, { + "name": "green", "text": "number", - "kind": "Primitive", - "name": "green" + "kind": "Primitive" }, { + "name": "blue", "text": "number", - "kind": "Primitive", - "name": "blue" + "kind": "Primitive" } ] } @@ -120,7 +120,7 @@ { "name": "redComponent", "kind": "Variable", - "line": 12, + "line": 11, "type": { "text": "number | undefined", "kind": "Union", @@ -140,7 +140,7 @@ { "name": "greenNormalized", "kind": "Variable", - "line": 13, + "line": 12, "type": { "text": "string", "kind": "Primitive" @@ -171,4 +171,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/variable/satisfies-operator/test.ts b/tests/variable/satisfies-operator/test.ts index 52fb30d1..c3248c80 100644 --- a/tests/variable/satisfies-operator/test.ts +++ b/tests/variable/satisfies-operator/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, updateExpectedOutput, test } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'variable'; const subcategory = 'satisfies-operator'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/variable/type-alias/output.json b/tests/variable/type-alias/output.json index eb32af4c..dd8ee76a 100644 --- a/tests/variable/type-alias/output.json +++ b/tests/variable/type-alias/output.json @@ -22,4 +22,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/variable/type-alias/test.ts b/tests/variable/type-alias/test.ts index 9d9e5c79..5e336ea1 100644 --- a/tests/variable/type-alias/test.ts +++ b/tests/variable/type-alias/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, test, updateExpectedOutput } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'variable'; const subcategory = 'type-alias'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); }); diff --git a/tests/variable/type-assertion/output.json b/tests/variable/type-assertion/output.json index 9c48d979..6335680a 100644 --- a/tests/variable/type-assertion/output.json +++ b/tests/variable/type-assertion/output.json @@ -78,4 +78,4 @@ } ] } -] +] \ No newline at end of file diff --git a/tests/variable/type-assertion/test.ts b/tests/variable/type-assertion/test.ts index d2434371..b351604b 100644 --- a/tests/variable/type-assertion/test.ts +++ b/tests/variable/type-assertion/test.ts @@ -1,13 +1,19 @@ -import { describe, expect, it } from 'vitest'; -import { getTestResult } from '../../utils.js'; +import { getTestResult, updateExpectedOutput, test } from '../../utils.js'; +import { describe, expect } from 'vitest'; const category = 'variable'; const subcategory = 'type-assertion'; const { actual, expected } = await getTestResult({ category, subcategory }); describe(`${category}/${subcategory}`, () => { - it('should reflect the expected modules', () => { + test('should reflect the expected modules', ({ update }) => { const result = actual.map(m => m.serialize()); + + if (update) { + updateExpectedOutput(result, category, subcategory); + return; + } + expect(result).to.deep.equal(expected); }); });