Socket
Socket
Sign inDemoInstall

@code-to-json/test-helpers

Package Overview
Dependencies
12
Maintainers
2
Versions
162
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @code-to-json/test-helpers

Test helpers for code-to-json


Version published
Weekly downloads
166
increased by4050%
Maintainers
2
Install size
61.1 MB
Created
Weekly downloads
 

Readme

Source

@code-to-json/test-helpers

Build Status Build Status Version codecov Total alerts

This package contains a variety of test helpers, useful for testing tools built on top of the TypeScript compiler API in general, and code-to-json in particular

Usage

createTempFixtureFolder

Create collection of files and folders in your OS system temp folder

You may either refer to an existing folder on disk

import { createTempFixtureFolder } from '@code-to-json/test-helpers';

// Create the test case in your system temp folder
const { rootPath, cleanup } = await createTempFixtureFolder('path/to/my/fixture/on/disk');

cleanup(); // Completely delete the test case from disk

or describe your fixture using a plain JS/TS object

import { createTempFixtureFolder } from '@code-to-json/test-helpers';

// Create the test case in your system temp folder
const { rootPath, cleanup } = await createTempFixtureFolder({
  // ./tsconfig.json
  'tsconfig.json': `
{
  "compilerOptions": {
    "noEmit": true,
    "module": "es6",
    "target": "es2015"
  },
  "include": ["src"]
}
  `,
  src: {
    // ./src/index.ts
    'index.ts': `
/**
* This is a variable with an explicit type
*/
const constWithExplicitType: string = 'foo';
`,
  },
});

cleanup(); // Completely delete the test case from disk

setupTestCase

Create the same folder structure described above for createTempFixtureFolder, and also initialize it as a TypeScript program.

import * as ts from 'typescript';
import { setupTestCase } from '@code-to-json/test-helpers';

// Create the test case in your system temp folder
const program: ts.Program = await setupTestCase(
  /**
   * Root folder of the fixture on disk
   * (you can also provide a "fixture object" as described above)
   */
  'path/to/my/fixture/on/disk',
  /**
   * One or more entry points of your application. Any imports will be included
   * in the TS program as well
   */
  ['src/index.ts'],
);

Versioning & Conventions

This library has a very strong commitment to semantic versioning, and makes use of conventional commits to automatically generate changelogs, and to increment version numbers appropriately when publishing.


© 2018 LinkedIn

FAQs

Last updated on 16 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc