test(plugin-tools): add some tests for the sanitizeMigrationName function

This commit is contained in:
Joakim Carlstein 2023-11-10 14:49:27 +01:00
parent 4e2a27ffeb
commit e159cd17bd
4 changed files with 149 additions and 2 deletions

View file

@ -53,7 +53,15 @@
"prettier": true,
"rules": {
"complexity": 0
},
"overrides": [
{
"files": "packages/**/*.test.ts",
"rules": {
"@typescript-eslint/no-floating-promises": 0
}
}
]
},
"dependencies": {
"@changesets/cli": "2.26.2",
@ -61,10 +69,12 @@
"@commitlint/config-conventional": "18.4.0",
"@manypkg/cli": "0.21.0",
"@types/node": "20.9.0",
"glob": "10.3.10",
"husky": "8.0.3",
"lint-staged": "15.0.2",
"npm-run-all": "4.1.5",
"prettier": "3.0.3",
"tsx": "4.1.0",
"turbo": "1.10.16",
"typescript": "5.2.2",
"vitest": "0.34.6",

View file

@ -20,7 +20,9 @@
},
"scripts": {
"build": "tsc --pretty",
"build:watch": "tsc --pretty --watch"
"build:watch": "tsc --pretty --watch",
"test": "glob -c \"node --import tsx --test-reporter spec --test\" \"./src/**/*.test.ts\"",
"test:watch": "glob -c \"node --watch --import tsx --test-reporter spec --test\" \"./src/**/*.test.ts\""
},
"keywords": [
"emigrate",

View file

@ -0,0 +1,38 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { sanitizeMigrationName } from './index.js';
describe('sanitizeMigrationName', () => {
it('should replace spaces with underscores', () => {
assert.strictEqual(sanitizeMigrationName('foo bar'), 'foo_bar');
});
it('should replace disallowed filename characters with underscores', () => {
assert.strictEqual(sanitizeMigrationName('foo>bar'), 'foo_bar');
assert.strictEqual(sanitizeMigrationName('foo<bar'), 'foo_bar');
assert.strictEqual(sanitizeMigrationName('foo?bar'), 'foo_bar');
assert.strictEqual(sanitizeMigrationName('foo:bar'), 'foo_bar');
assert.strictEqual(sanitizeMigrationName('foo/bar'), 'foo_bar');
assert.strictEqual(sanitizeMigrationName('foo\\bar'), 'foo_bar');
assert.strictEqual(sanitizeMigrationName('foo*bar'), 'foo_bar');
assert.strictEqual(sanitizeMigrationName('foo|bar'), 'foo_bar');
assert.strictEqual(sanitizeMigrationName('foo"bar'), 'foo_bar');
assert.strictEqual(sanitizeMigrationName("foo'bar"), 'foo_bar');
});
it('should replace consecutive disallowed characters with only one underscore', () => {
assert.strictEqual(sanitizeMigrationName('foo? :bar'), 'foo_bar');
});
it('should remove leading disallowed characters', () => {
assert.strictEqual(sanitizeMigrationName('_? :*<>foo'), 'foo');
});
it('should remove trailing disallowed characters', () => {
assert.strictEqual(sanitizeMigrationName('foo_? :*<>'), 'foo');
});
it('should lower case the filename', () => {
assert.strictEqual(sanitizeMigrationName('Are you, Foo?'), 'are_you_foo');
});
});

97
pnpm-lock.yaml generated
View file

@ -23,6 +23,9 @@ importers:
'@types/node':
specifier: 20.9.0
version: 20.9.0
glob:
specifier: 10.3.10
version: 10.3.10
husky:
specifier: 8.0.3
version: 8.0.3
@ -35,6 +38,9 @@ importers:
prettier:
specifier: 3.0.3
version: 3.0.3
tsx:
specifier: 4.1.0
version: 4.1.0
turbo:
specifier: 1.10.16
version: 1.10.16
@ -719,6 +725,18 @@ packages:
resolution: {integrity: sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==}
dev: false
/@isaacs/cliui@8.0.2:
resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==}
engines: {node: '>=12'}
dependencies:
string-width: 5.1.2
string-width-cjs: /string-width@4.2.3
strip-ansi: 7.1.0
strip-ansi-cjs: /strip-ansi@6.0.1
wrap-ansi: 8.1.0
wrap-ansi-cjs: /wrap-ansi@7.0.0
dev: false
/@jest/schemas@29.6.3:
resolution: {integrity: sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
@ -851,6 +869,13 @@ packages:
fastq: 1.15.0
dev: false
/@pkgjs/parseargs@0.11.0:
resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==}
engines: {node: '>=14'}
requiresBuild: true
dev: false
optional: true
/@pkgr/utils@2.4.2:
resolution: {integrity: sha512-POgTXhjrTfbTV63DiFXav4lBHiICLKKwDeaKn9Nphwj7WH6m0hMMCaJkMyRWjgtPFyRKRVoMXXjczsTQRDEhYw==}
engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0}
@ -1494,6 +1519,12 @@ packages:
concat-map: 0.0.1
dev: false
/brace-expansion@2.0.1:
resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==}
dependencies:
balanced-match: 1.0.2
dev: false
/braces@3.0.2:
resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==}
engines: {node: '>=8'}
@ -2776,6 +2807,14 @@ packages:
is-callable: 1.2.7
dev: false
/foreground-child@3.1.1:
resolution: {integrity: sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==}
engines: {node: '>=14'}
dependencies:
cross-spawn: 7.0.3
signal-exit: 4.1.0
dev: false
/fs-extra@11.1.1:
resolution: {integrity: sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==}
engines: {node: '>=14.14'}
@ -2929,6 +2968,18 @@ packages:
resolution: {integrity: sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==}
dev: false
/glob@10.3.10:
resolution: {integrity: sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==}
engines: {node: '>=16 || 14 >=14.17'}
hasBin: true
dependencies:
foreground-child: 3.1.1
jackspeak: 2.3.6
minimatch: 9.0.3
minipass: 7.0.4
path-scurry: 1.10.1
dev: false
/glob@7.2.3:
resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==}
dependencies:
@ -3471,6 +3522,15 @@ packages:
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
dev: false
/jackspeak@2.3.6:
resolution: {integrity: sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==}
engines: {node: '>=14'}
dependencies:
'@isaacs/cliui': 8.0.2
optionalDependencies:
'@pkgjs/parseargs': 0.11.0
dev: false
/jest-worker@27.5.1:
resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==}
engines: {node: '>= 10.13.0'}
@ -3793,6 +3853,11 @@ packages:
engines: {node: '>=8'}
dev: false
/lru-cache@10.0.1:
resolution: {integrity: sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==}
engines: {node: 14 || >=16.14}
dev: false
/lru-cache@4.1.5:
resolution: {integrity: sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==}
dependencies:
@ -3931,6 +3996,13 @@ packages:
brace-expansion: 1.1.11
dev: false
/minimatch@9.0.3:
resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==}
engines: {node: '>=16 || 14 >=14.17'}
dependencies:
brace-expansion: 2.0.1
dev: false
/minimist-options@4.1.0:
resolution: {integrity: sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A==}
engines: {node: '>= 6'}
@ -3944,6 +4016,11 @@ packages:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
dev: false
/minipass@7.0.4:
resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==}
engines: {node: '>=16 || 14 >=14.17'}
dev: false
/mixme@0.5.9:
resolution: {integrity: sha512-VC5fg6ySUscaWUpI4gxCBTQMH2RdUpNrk+MsbpCYtIvf9SBJdiUey4qE7BXviJsJR4nDQxCZ+3yaYNW3guz/Pw==}
engines: {node: '>= 8.0.0'}
@ -4285,6 +4362,14 @@ packages:
resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==}
dev: false
/path-scurry@1.10.1:
resolution: {integrity: sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==}
engines: {node: '>=16 || 14 >=14.17'}
dependencies:
lru-cache: 10.0.1
minipass: 7.0.4
dev: false
/path-type@3.0.0:
resolution: {integrity: sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==}
engines: {node: '>=4'}
@ -5230,6 +5315,18 @@ packages:
resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==}
dev: false
/tsx@4.1.0:
resolution: {integrity: sha512-u4l17Yd63Wsk2fzNn1wZCmcS9kwJ/2ysl7wuoVggv2hd3NjLA5JQPpyJMXoWSXOwOvoQUzNcu/sf/35HEsnXsg==}
engines: {node: '>=18.0.0'}
hasBin: true
dependencies:
esbuild: 0.18.20
get-tsconfig: 4.7.2
source-map-support: 0.5.21
optionalDependencies:
fsevents: 2.3.3
dev: false
/tty-table@4.2.3:
resolution: {integrity: sha512-Fs15mu0vGzCrj8fmJNP7Ynxt5J7praPXqFN0leZeZBXJwkMxv9cb2D454k1ltrtUSJbZ4yH4e0CynsHLxmUfFA==}
engines: {node: '>=8.0.0'}