-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: replace tap with built-in test runner
- Loading branch information
1 parent
4d30bfd
commit f1a34ba
Showing
28 changed files
with
11,019 additions
and
23,556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
.idea | ||
.tap | ||
node_modules | ||
package-lock.json | ||
test/entities.ts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
const childProcess = require('node:child_process') | ||
const fs = require('node:fs') | ||
const path = require('node:path') | ||
const t = require('tap') | ||
const { getTestPostgresConnectionString } = require('./helpers/setup-postgres.js') | ||
const test = require('node:test') | ||
const assert = require('node:assert/strict') | ||
|
||
const connection = getTestPostgresConnectionString() | ||
const ssl = process.env.DATABASE_SSL_ENABLED === 'true' | ||
|
||
t.test('help', t => { | ||
t.plan(1) | ||
|
||
test('help', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), '--help'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -23,15 +22,11 @@ t.test('help', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result) | ||
}) | ||
}) | ||
|
||
t.test('version', t => { | ||
t.plan(1) | ||
|
||
t.cleanSnapshot = s => s.replace(/v[0-9.]+/g, 'v{v}') | ||
|
||
test('version', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), '--version'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -45,13 +40,11 @@ t.test('version', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
assert.ok(/v[0-9.]+/.test(result.data)) | ||
}) | ||
}) | ||
|
||
t.test('missing connection string', t => { | ||
t.plan(1) | ||
|
||
test('missing connection string', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js')], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -65,13 +58,11 @@ t.test('missing connection string', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result) | ||
}) | ||
}) | ||
|
||
t.test('generates types stdout', t => { | ||
t.plan(1) | ||
|
||
test('generates types stdout', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : ''], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -85,13 +76,11 @@ t.test('generates types stdout', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result) | ||
}) | ||
}) | ||
|
||
t.test('generates types to file', t => { | ||
t.plan(1) | ||
|
||
test('generates types to file', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), '-o', './entities.ts', connection, ssl ? '--ssl' : ''], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -102,14 +91,12 @@ t.test('generates types to file', t => { | |
child.on('close', () => { | ||
const outputPath = path.join(__dirname, './entities.ts') | ||
const result = fs.readFileSync(outputPath, 'utf8') | ||
t.matchSnapshot(result) | ||
t.assert.snapshot(result) | ||
fs.unlinkSync(outputPath) | ||
}) | ||
}) | ||
|
||
t.test('reports success to stdout', t => { | ||
t.plan(1) | ||
|
||
test('reports success to stdout', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), '-o', './entities.ts', connection, ssl ? '--ssl' : ''], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -123,13 +110,11 @@ t.test('reports success to stdout', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.equal(result.data, '✔ Generated types from 10 tables and 4 enums\n') | ||
assert.equal(result.data, '✔ Generated types from 10 tables and 4 enums\n') | ||
}) | ||
}) | ||
|
||
t.test('generates types with exclusion', t => { | ||
t.plan(1) | ||
|
||
test('generates types with exclusion', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '-e', 'types,snake_test'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -143,13 +128,11 @@ t.test('generates types with exclusion', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('generates types with header', t => { | ||
t.plan(1) | ||
|
||
test('generates types with header', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '-h', '/* eslint-disable */'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -163,13 +146,11 @@ t.test('generates types with header', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('generates types with pascal case enums', t => { | ||
t.plan(1) | ||
|
||
test('generates types with pascal case enums', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '--pascal-enums'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -183,13 +164,11 @@ t.test('generates types with pascal case enums', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('generates types with noSemi option', t => { | ||
t.plan(1) | ||
|
||
test('generates types with noSemi option', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '--noSemi'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -203,13 +182,11 @@ t.test('generates types with noSemi option', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('generates types with no-semicolons option', t => { | ||
t.plan(1) | ||
|
||
test('generates types with no-semicolons option', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '--no-semicolons'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -223,13 +200,11 @@ t.test('generates types with no-semicolons option', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('generates types with semicolons option', t => { | ||
t.plan(1) | ||
|
||
test('generates types with semicolons option', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '--semicolons'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -243,13 +218,11 @@ t.test('generates types with semicolons option', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('generates types with bigint option', t => { | ||
t.plan(1) | ||
|
||
test('generates types with bigint option', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '--bigint'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -263,13 +236,11 @@ t.test('generates types with bigint option', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('generates types with types option', t => { | ||
t.plan(1) | ||
|
||
test('generates types with types option', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '--type'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -283,13 +254,11 @@ t.test('generates types with types option', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('generates types with insert types', t => { | ||
t.plan(1) | ||
|
||
test('generates types with insert types', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '--insert-types'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -303,13 +272,11 @@ t.test('generates types with insert types', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('generates table names', t => { | ||
t.plan(1) | ||
|
||
test('generates table names', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '--table-names'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -323,13 +290,11 @@ t.test('generates table names', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('generates view names', t => { | ||
t.plan(1) | ||
|
||
test('generates view names', t => { | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), connection, ssl ? '--ssl' : '', '--view-names'], { | ||
cwd: __dirname, | ||
env: process.env, | ||
|
@@ -343,12 +308,11 @@ t.test('generates view names', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.matchSnapshot(result.data) | ||
t.assert.snapshot(result.data) | ||
}) | ||
}) | ||
|
||
t.test('sends error to stderr', t => { | ||
t.plan(1) | ||
test('sends error to stderr', t => { | ||
const invalidConnection = 'postgres://postgres:[email protected]:1/test_db' | ||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..', 'src', 'index.js'), '-o', './entities.ts', invalidConnection, ssl ? '--ssl' : ''], { | ||
cwd: __dirname, | ||
|
@@ -363,6 +327,6 @@ t.test('sends error to stderr', t => { | |
}) | ||
|
||
child.on('close', () => { | ||
t.ok(result.data.includes('Error'), `${result.data} is not the expected error`) | ||
assert.ok(result.data.includes('Error'), `${result.data} is not the expected error`) | ||
}) | ||
}) |
Oops, something went wrong.