Skip to content

Commit 0ab4fdd

Browse files
committed
test: add more test cases
1 parent 583489b commit 0ab4fdd

File tree

10 files changed

+80
-56
lines changed

10 files changed

+80
-56
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ dist
1212
lib
1313
node_modules
1414
packages/*/src/languages.ts
15+
/test.*

packages/sh/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"prettier": "^3.0.3"
5151
},
5252
"dependencies": {
53-
"@reteps/dockerfmt": "^0.3.2",
53+
"@reteps/dockerfmt": "^0.3.4",
5454
"sh-syntax": "^0.5.6"
5555
},
5656
"devDependencies": {

packages/sh/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type Node,
66
type ParseError,
77
type ShOptions,
8-
type ShPrintOptions as ShFormatOptions,
8+
type ShPrintOptions,
99
processor,
1010
} from 'sh-syntax'
1111

@@ -22,7 +22,9 @@ export interface ShParserOptions
2222
filepath: string
2323
}
2424

25-
export interface ShPrintOptions extends ShFormatOptions {
25+
export type { ShPrintOptions }
26+
27+
export interface ShPrinterOptions extends ShPrintOptions {
2628
filepath: string
2729
tabWidth: number
2830
}

packages/sh/test/__snapshots__/fixtures.spec.ts.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,9 @@ exports[`parser and printer > should format 398.Dockerfile fixtures > 398.Docker
881881
"
882882
`;
883883
884-
exports[`parser and printer > should format 441.Dockerfile fixtures > 441.Dockerfile 1`] = `
885-
"RUN # install dependencies
884+
exports[`parser and printer > should format 441.Dockerfile fixtures - {"indent":4} > 441.Dockerfile 1`] = `
885+
"RUN \\
886+
# install dependencies
886887
NODE_ENV=production npm install-clean \\
887888
# cleanup
888889
&& /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup

packages/sh/test/fixtures.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import { format } from 'prettier'
55

66
import * as sh from 'prettier-plugin-sh'
77

8+
const PARSER_OPTIONS: Partial<
9+
Record<string, Omit<sh.ShPrintOptions, 'originalText'>>
10+
> = {
11+
441: {
12+
indent: 4,
13+
},
14+
}
15+
816
const _dirname = import.meta.dirname
917

1018
describe('parser and printer', () => {
@@ -14,11 +22,19 @@ describe('parser and printer', () => {
1422
const filepath = path.resolve(fixtures, relativeFilepath)
1523
const input = fs.readFileSync(filepath, 'utf8')
1624

17-
it(`should format ${relativeFilepath} fixtures`, async () => {
25+
const caseName = relativeFilepath.slice(
26+
0,
27+
relativeFilepath.lastIndexOf('.'),
28+
)
29+
30+
const overrideOptions = PARSER_OPTIONS[caseName]
31+
32+
it(`should format ${relativeFilepath} fixtures${overrideOptions ? ' - ' + JSON.stringify(overrideOptions) : ''}`, async () => {
1833
try {
1934
const output = await format(input, {
2035
filepath,
2136
plugins: [sh],
37+
...overrideOptions,
2238
})
2339

2440
expect(output).toMatchSnapshot(relativeFilepath)

packages/sql/test/__snapshots__/fixtures.spec.ts.snap

Lines changed: 15 additions & 7 deletions
Large diffs are not rendered by default.

packages/sql/test/fixtures.spec.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import fs from 'node:fs'
22
import path from 'node:path'
3-
import { fileURLToPath } from 'node:url'
43

54
import { format } from 'prettier'
65
import { type ParamTypes, postgresql } from 'sql-formatter'
76

8-
import SqlPlugin, { type SqlFormatOptions } from 'prettier-plugin-sql'
7+
import sql, { type SqlFormatOptions } from 'prettier-plugin-sql'
98

10-
const PARSER_OPTIONS: Record<string, SqlFormatOptions> = {
9+
const PARSER_OPTIONS: Partial<Record<string, SqlFormatOptions>> = {
1110
144: {
1211
language: 'postgresql',
1312
},
@@ -35,33 +34,38 @@ const PARSER_OPTIONS: Record<string, SqlFormatOptions> = {
3534
334: {
3635
dialect: JSON.stringify(postgresql),
3736
},
37+
405: {
38+
language: 'postgresql',
39+
},
3840
}
3941

40-
const _dirname =
41-
typeof __dirname === 'undefined'
42-
? path.dirname(fileURLToPath(import.meta.url))
43-
: __dirname
42+
const _dirname = import.meta.dirname
4443

4544
describe('parser and printer', () => {
46-
it('should format all fixtures', async () => {
47-
const fixtures = path.resolve(_dirname, 'fixtures')
48-
for (const filepath of fs.readdirSync(fixtures)) {
49-
const input = fs.readFileSync(path.resolve(fixtures, filepath)).toString()
45+
const fixtures = path.resolve(_dirname, 'fixtures')
46+
for (const relativeFilepath of fs.readdirSync(fixtures)) {
47+
const filepath = path.resolve(fixtures, relativeFilepath)
48+
const input = fs.readFileSync(filepath).toString()
49+
50+
const caseName = relativeFilepath.slice(
51+
0,
52+
relativeFilepath.lastIndexOf('.'),
53+
)
5054

51-
const caseName = filepath.slice(0, filepath.lastIndexOf('.'))
55+
const overrideOptions = PARSER_OPTIONS[caseName]
5256

57+
it(`should format ${relativeFilepath} fixtures${overrideOptions ? ' - ' + JSON.stringify(overrideOptions) : ''}`, async () => {
5358
try {
5459
const output = await format(input, {
5560
filepath,
56-
parser: 'sql',
57-
plugins: [SqlPlugin],
58-
...PARSER_OPTIONS[caseName],
61+
plugins: [sql],
62+
...overrideOptions,
5963
})
6064

61-
expect(output).toMatchSnapshot(filepath)
65+
expect(output).toMatchSnapshot(relativeFilepath)
6266
} catch (error) {
63-
expect(error).toMatchSnapshot(filepath)
67+
expect(error).toMatchSnapshot(relativeFilepath)
6468
}
65-
}
66-
})
69+
})
70+
}
6771
})

packages/sql/test/fixtures/405.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE DOMAIN "public"."address_postal_code" AS text NOT NULL CONSTRAINT "br_postal_code_check" CHECK ((VALUE ~ '^\d{5}$'::text) OR (VALUE ~ '^\d{8}$'::text));

test.js

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

yarn.lock

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4015,10 +4015,10 @@ __metadata:
40154015
languageName: node
40164016
linkType: hard
40174017

4018-
"@reteps/dockerfmt@npm:^0.3.2":
4019-
version: 0.3.2
4020-
resolution: "@reteps/dockerfmt@npm:0.3.2"
4021-
checksum: 10c0/dadb4f9f8c4ef1c5d448c793096237fc86362c98324d4206a0e655901bb6d8e4c7d8ae1e5e38815bc09ffbbf3fd8a079edb8006b1e034cbeb5c9bd1955ef0d26
4018+
"@reteps/dockerfmt@npm:^0.3.4":
4019+
version: 0.3.4
4020+
resolution: "@reteps/dockerfmt@npm:0.3.4"
4021+
checksum: 10c0/f270e221267d0ea3957a58b2a24291c70b98cdfda14131b736d61363a7c9f89936e0c5da8196743b27d5dda397f8a7805c9afad827bfbe2489b0b02a1391b53a
40224022
languageName: node
40234023
linkType: hard
40244024

@@ -5179,18 +5179,17 @@ __metadata:
51795179
linkType: hard
51805180

51815181
"@vitest/eslint-plugin@npm:^1.1.39":
5182-
version: 1.1.40
5183-
resolution: "@vitest/eslint-plugin@npm:1.1.40"
5182+
version: 1.1.42
5183+
resolution: "@vitest/eslint-plugin@npm:1.1.42"
51845184
peerDependencies:
5185+
"@typescript-eslint/utils": ">= 8.24.0"
51855186
eslint: ">= 8.57.0"
51865187
typescript: ">= 5.0.0"
51875188
vitest: "*"
51885189
peerDependenciesMeta:
51895190
typescript:
51905191
optional: true
5191-
vitest:
5192-
optional: true
5193-
checksum: 10c0/2cc7c2242d106fdb5fd97f85b7d94466b6c5db414e38e1a7224ce446800fcd661a36148a6b4580d362398720ba0b6faec843f2cbcff04fc4ef19141d29e03f1a
5192+
checksum: 10c0/55eb0e56a514059190402a07fd1ac9786ae050bc22d6874d8fb1259feabd86e9d4bb879b8910a0a32aefb0e88740f7dfcd8d1033755aa561e04c8ead04867bf9
51945193
languageName: node
51955194
linkType: hard
51965195

@@ -7459,9 +7458,9 @@ __metadata:
74597458
linkType: hard
74607459

74617460
"dotenv@npm:^16.3.1":
7462-
version: 16.4.7
7463-
resolution: "dotenv@npm:16.4.7"
7464-
checksum: 10c0/be9f597e36a8daf834452daa1f4cc30e5375a5968f98f46d89b16b983c567398a330580c88395069a77473943c06b877d1ca25b4afafcdd6d4adb549e8293462
7461+
version: 16.5.0
7462+
resolution: "dotenv@npm:16.5.0"
7463+
checksum: 10c0/5bc94c919fbd955bf0ba44d33922a1e93d1078e64a1db5c30faeded1d996e7a83c55332cb8ea4fae5a9ca4d0be44cbceb95c5811e70f9f095298df09d1997dd9
74657464
languageName: node
74667465
linkType: hard
74677466

@@ -7498,9 +7497,9 @@ __metadata:
74987497
linkType: hard
74997498

75007499
"electron-to-chromium@npm:^1.5.73":
7501-
version: 1.5.135
7502-
resolution: "electron-to-chromium@npm:1.5.135"
7503-
checksum: 10c0/d431751080e659dd089423cbf7e5efcd1c6672a06b9552b2ebfb80caf0e2c442a2ee883f445f70ffb53c4f740b3fe8f6607760d9a15d6db2d3ba44dff39fc901
7500+
version: 1.5.136
7501+
resolution: "electron-to-chromium@npm:1.5.136"
7502+
checksum: 10c0/6a207e397638b0428b31c87d409a73f6bd953598cb7359ee4c3c175e645c3ae0cc99fc5128eaca19e2f1052200fd016eb4bb1012a55e5824eb1dce85b0396184
75047503
languageName: node
75057504
linkType: hard
75067505

@@ -14026,7 +14025,7 @@ __metadata:
1402614025
version: 0.0.0-use.local
1402714026
resolution: "prettier-plugin-sh@workspace:packages/sh"
1402814027
dependencies:
14029-
"@reteps/dockerfmt": "npm:^0.3.2"
14028+
"@reteps/dockerfmt": "npm:^0.3.4"
1403014029
"@types/common-tags": "npm:^1.8.4"
1403114030
common-tags: "npm:^1.8.2"
1403214031
sh-syntax: "npm:^0.5.6"

0 commit comments

Comments
 (0)