{"id":17816307,"url":"https://github.com/dgellow/plugin-test-internal","last_synced_at":"2026-02-02T23:03:23.099Z","repository":{"id":42721841,"uuid":"253305744","full_name":"dgellow/plugin-test-internal","owner":"dgellow","description":"🕵️‍♀️ JS/TS compilers plugin to safely export internal functions and variables, for testing or meta programming purpose","archived":false,"fork":false,"pushed_at":"2024-06-18T12:13:25.000Z","size":812,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-19T04:09:12.331Z","etag":null,"topics":["babel-plugin","babel7","testing","typescript","typescript-transformer"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dgellow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-05T18:37:18.000Z","updated_at":"2024-06-18T12:13:26.000Z","dependencies_parsed_at":"2024-06-18T14:21:17.830Z","dependency_job_id":null,"html_url":"https://github.com/dgellow/plugin-test-internal","commit_stats":{"total_commits":36,"total_committers":2,"mean_commits":18.0,"dds":"0.36111111111111116","last_synced_commit":"e51da8dc5268c2a7640fa34a5abf1bbae15bada4"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgellow%2Fplugin-test-internal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgellow%2Fplugin-test-internal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgellow%2Fplugin-test-internal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgellow%2Fplugin-test-internal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgellow","download_url":"https://codeload.github.com/dgellow/plugin-test-internal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221705281,"owners_count":16866928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babel-plugin","babel7","testing","typescript","typescript-transformer"],"created_at":"2024-10-27T16:37:17.502Z","updated_at":"2026-02-02T23:03:23.022Z","avatar_url":"https://github.com/dgellow.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Test the internals of a JS or TS module [![Build Status](https://travis-ci.org/dgellow/plugin-test-internal.svg?branch=master)](https://travis-ci.org/dgellow/plugin-test-internal)\n\nAvailable as\n- a babel plugin [![npm version](https://badge.fury.io/js/babel-plugin-test-internal.svg)](https://badge.fury.io/js/babel-plugin-test-internal)\n- a typescript compiler extension [![npm version](https://badge.fury.io/js/typescript-plugin-test-internal.svg)](https://badge.fury.io/js/typescript-plugin-test-internal)\n\n## Usage\n\n### Babel plugin\n\n1. Install package\n```sh\n$ npm install -D babel-plugin-test-internal\n$ yarn add -D babel-plugin-test-internal\n```\n\n2. Add the plugin to Babel configuration in your `babel.config.js`\n\n```js\n// configuration example\n\nmodule.exports = api =\u003e {\n  //  1. 👇 are we in a test context?\n  const isTest = api.env('test')\n  // 2. if yes register the plugin 👇\n  const plugins = isTest ? [\"test-internal\"]: []\n\n  return {\n  presets: [\n  \"@babel/preset-env\",\n  \"@babel/preset-typescript\",\n  \"@babel/preset-react\",\n  ],\n  plugins, // 👈  3. don't forget to add the plugins property to the configuration object\n  }\n}\n```\n\n3. In your code, where you want to use internal content (i.e: your tests)\n\n```js\n// 1. 👇 import __internal__ from the module you want to test\nimport {__internal__} from \"./your-file\"\n\ntest(\"testing some internal things\", () =\u003e {\n  const expected = ...\n  // 2. use properties you need 👇\n  assert(__internal__.doSomething(), expected)\n})\n```\n\n### Typescript compiler plugin\n\n1. Install package\n\n```\n$ npm install -D typescript-plugin-test-internal\n$ yarn add -D typescript-plugin-test-internal\n```\n\n2. Add the plugin to [ts-loader](https://github.com/TypeStrong/ts-loader/) configuration in your `webpack.config.js`\n\n```js\n// configuration example\n\n// 👇 1. import the plugin\nconst testInternalTranformer = require('typescript-plugin-test-internal').default;\n\nmodule.exports = {\n  mode: 'development',\n  entry: './index.ts',\n  module: {\n    rules: [\n      {\n        test: /\\.ts$/,\n        loader: 'ts-loader',\n        options: { // 👈 2. add ts-loader 'options' object\n          // 3. 👇 add the method 'getCustomTransformers'\n          getCustomTransformers: program =\u003e ({\n            // 4. register the plugin 👇\n            before: [testInternalTransformer(program)]\n          })\n        }\n      }\n    ]\n  }\n}\n```\n\n3. In your code, where you want to use internal content (i.e: your tests)\n\n```ts\n// 1. 👇 import '__internal__' from the module you want to test\nimport {__internal__} from \"./your-file\"\n\ntest(\"testing some internal things\", () =\u003e {\n  const expected = ...\n  // 2. use properties you need 👇\n  assert(__internal__.doSomething(), expected)\n})\n```\n\n## Development\n\nInstall all dependencies, build and test everything\n\n```sh\n# from the project root\n$ yarn install\n$ yarn build\n$ yarn test\n```\n\n### Babel plugin\n\n```sh\n$ cd ./babel\n$ yarn install\n$ yarn test\n$ yarn build\n```\n\n### Typescript plugin\n\n```sh\n$ cd ./typescript\n$ yarn install\n$ yarn test\n$ yarn build\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgellow%2Fplugin-test-internal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgellow%2Fplugin-test-internal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgellow%2Fplugin-test-internal/lists"}