Skip to content

Commit

Permalink
test: introduce basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Korzunin committed Sep 12, 2021
1 parent 45d8f33 commit 97c622a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ ignorePatterns:
- dist
- plop
- prisma
- jest.config.js
plugins:
- jest
- '@typescript-eslint'
parserOptions:
ecmaVersion: 9
sourceType: module
project: ./tsconfig.json
extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
- plugin:jest/recommended
- plugin:jest/style
- plugin:eslint-comments/recommended
- prettier
rules:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ dist/

# Prisma related files
dmmf.json

# Test artifacts
.testArtifacts
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@types/jest": "^27.0.1",
"@types/node": "^14.17.9",
"@types/ramda": "^0.27.44",
"@types/temp": "^0.9.1",
"@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^4.29.2",
"eslint": "^7.32.0",
Expand All @@ -56,6 +57,7 @@
"prettier": "^2.3.2",
"prisma": "^2.29.1",
"semantic-release": "^17.4.5",
"temp": "^0.9.4",
"ts-jest": "^27.0.5",
"typescript": "^4.3.5"
},
Expand Down
41 changes: 41 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { getGenerator } from '@prisma/sdk';
import temp from 'temp';
import path from 'path';
import fs from 'fs';

describe('given prisma-sequelize-generator,', () => {
beforeAll(() => {
temp.track();
});

afterAll(() => {
temp.cleanupSync();
});

it('should generate models.', async () => {
expect.hasAssertions();

const mockDir = temp.mkdirSync({ dir: path.join(__dirname, '../.testArtifacts') });

const generator = await getGenerator({
schemaPath: path.join(__dirname, '../prisma/schema.prisma'),
baseDir: mockDir,
printDownloadProgress: false,
skipDownload: true,
});

await generator.generate();

const expectedDir = path.join(mockDir, 'sequelize');
expect(fs.existsSync(expectedDir)).toBe(true);
expect(fs.existsSync(path.join(expectedDir, 'index.ts'))).toBe(true);
expect(fs.existsSync(path.join(expectedDir, 'config.json'))).toBe(true);
expect(fs.existsSync(path.join(expectedDir, 'models', 'index.ts'))).toBe(true);
expect(fs.existsSync(path.join(expectedDir, 'models', 'Post.ts'))).toBe(true);
expect(fs.existsSync(path.join(expectedDir, 'models', 'User.ts'))).toBe(true);
expect(fs.existsSync(path.join(expectedDir, 'utils', 'index.ts'))).toBe(true);
expect(fs.existsSync(path.join(expectedDir, 'utils', 'find.ts'))).toBe(true);

generator.stop();
});
});
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"strictFunctionTypes": true
},
"include": [
"src"
"src/**/*.ts",
"tests/**/*.ts"
],
"exclude": [
"node_modules"
Expand Down

0 comments on commit 97c622a

Please sign in to comment.