-
Notifications
You must be signed in to change notification settings - Fork 36
test: setup test-helpers package #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # test-helpers | ||
|
|
||
| This library was generated with [Nx](https://nx.dev). | ||
|
|
||
| ## Building | ||
|
|
||
| Run `nx build test-helpers` to build the library. | ||
|
|
||
| ## Running unit tests | ||
|
|
||
| Run `nx test test-helpers` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| const baseConfig = require('../eslint.config.js'); | ||
|
|
||
| module.exports = [ | ||
| ...baseConfig, | ||
| { | ||
| files: ['**/*.json'], | ||
| rules: { | ||
| '@nx/dependency-checks': [ | ||
| 'error', | ||
| { | ||
| ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'], | ||
| // TODO: @nx/dependency-checks incorrectly reports unused dependencies | ||
| checkObsoleteDependencies: false, | ||
| }, | ||
| ], | ||
| }, | ||
| languageOptions: { | ||
| parser: require('jsonc-eslint-parser'), | ||
| }, | ||
| }, | ||
| ]; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export default { | ||
| displayName: 'test-helpers', | ||
| preset: '../jest.preset.js', | ||
| testEnvironment: 'node', | ||
| transform: { | ||
| '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
| }, | ||
| moduleFileExtensions: ['ts', 'js', 'html'], | ||
| coverageDirectory: '../coverage/test-helpers', | ||
| }; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "name": "test-helpers", | ||
| "version": "0.0.1", | ||
| "dependencies": { | ||
| "tslib": "^2.3.0" | ||
| }, | ||
| "type": "commonjs", | ||
| "main": "./src/index.js", | ||
| "typings": "./src/index.d.ts", | ||
| "private": true | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "test-helpers", | ||
| "$schema": "../node_modules/nx/schemas/project-schema.json", | ||
| "sourceRoot": "test-helpers/src", | ||
| "projectType": "library", | ||
| "tags": [], | ||
| "targets": { | ||
| "build": { | ||
| "executor": "@nx/js:tsc", | ||
| "outputs": ["{options.outputPath}"], | ||
| "options": { | ||
| "outputPath": "dist/test-helpers", | ||
| "main": "test-helpers/src/index.ts", | ||
| "tsConfig": "test-helpers/tsconfig.lib.json", | ||
| "assets": ["test-helpers/*.md"] | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './lib/test-helpers'; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { writeFiles, getTempDirectory, cleanup } from './test-helpers'; | ||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
|
|
||
| test('writeFiles in temp directory with cleanup', () => { | ||
| const directory = getTempDirectory('test_helpers'); | ||
| const files = { | ||
| 'package.json': '{}', | ||
| 'dir/file.js': 'module.exports = "x";', | ||
| }; | ||
|
|
||
| writeFiles(directory, files); | ||
|
|
||
| expect(fs.readFileSync(path.join(directory, 'package.json'), 'utf8')).toBe( | ||
| '{}' | ||
| ); | ||
| expect(fs.readFileSync(path.join(directory, 'dir', 'file.js'), 'utf8')).toBe( | ||
| 'module.exports = "x";' | ||
| ); | ||
|
|
||
| cleanup(directory); | ||
|
|
||
| expect(fs.existsSync(directory)).toBe(false); | ||
| }); |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import * as fs from 'node:fs'; | ||
| import * as path from 'node:path'; | ||
| import * as os from 'node:os'; | ||
| import { createDirectory } from 'jest-util'; | ||
|
|
||
| export const getTempDirectory = (name: string) => | ||
| path.resolve(os.tmpdir(), name); | ||
|
|
||
| export const cleanup = (directory: string) => { | ||
| fs.rmSync(directory, { recursive: true, force: true, maxRetries: 10 }); | ||
| }; | ||
|
|
||
| /** | ||
| * Creates a nested directory with files and their contents | ||
| * writeFiles( | ||
| * '/home/tmp', | ||
| * { | ||
| * 'package.json': '{}', | ||
| * 'dir/file.js': 'module.exports = "x";', | ||
| * } | ||
| * ); | ||
| */ | ||
| export const writeFiles = ( | ||
| directory: string, | ||
| files: { [filename: string]: string | NodeJS.ArrayBufferView } | ||
| ) => { | ||
| createDirectory(directory); | ||
|
|
||
| Object.keys(files).forEach((fileOrPath) => { | ||
| const dirname = path.dirname(fileOrPath); | ||
|
|
||
| if (dirname !== '/') { | ||
| createDirectory(path.join(directory, dirname)); | ||
| } | ||
| fs.writeFileSync( | ||
| path.resolve(directory, ...fileOrPath.split('/')), | ||
| files[fileOrPath] | ||
| ); | ||
| }); | ||
| }; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "extends": "../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "forceConsistentCasingInFileNames": true, | ||
| "strict": true, | ||
| "noImplicitOverride": true, | ||
| "noPropertyAccessFromIndexSignature": true, | ||
| "noImplicitReturns": true, | ||
| "noFallthroughCasesInSwitch": true | ||
| }, | ||
| "files": [], | ||
| "include": [], | ||
| "references": [ | ||
| { | ||
| "path": "./tsconfig.lib.json" | ||
| }, | ||
| { | ||
| "path": "./tsconfig.spec.json" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "outDir": "../dist/out-tsc", | ||
| "declaration": true, | ||
| "types": ["node"] | ||
| }, | ||
| "include": ["src/**/*.ts"], | ||
| "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "outDir": "../dist/out-tsc", | ||
| "module": "commonjs", | ||
| "types": ["jest", "node"] | ||
| }, | ||
| "include": [ | ||
| "jest.config.ts", | ||
| "src/**/*.test.ts", | ||
| "src/**/*.spec.ts", | ||
| "src/**/*.d.ts" | ||
| ] | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not publishable, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, it's a private package