{"id":17435431,"url":"https://github.com/kazu69/export-context","last_synced_at":"2025-06-30T21:04:52.584Z","repository":{"id":143878676,"uuid":"71157396","full_name":"kazu69/export-context","owner":"kazu69","description":"Executing not exported js code and browser js code in a Sandbox With Node's VM Module","archived":false,"fork":false,"pushed_at":"2020-03-23T23:36:51.000Z","size":303,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-29T01:59:17.349Z","etag":null,"topics":["context","dom","esnext","javascript","testing","unit-testing"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/export-context","language":"JavaScript","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/kazu69.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":"2016-10-17T16:15:02.000Z","updated_at":"2020-03-23T23:36:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d7be0bf-de89-44eb-b61c-484400acf181","html_url":"https://github.com/kazu69/export-context","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/kazu69/export-context","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazu69%2Fexport-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazu69%2Fexport-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazu69%2Fexport-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazu69%2Fexport-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kazu69","download_url":"https://codeload.github.com/kazu69/export-context/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazu69%2Fexport-context/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262850257,"owners_count":23374351,"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":["context","dom","esnext","javascript","testing","unit-testing"],"created_at":"2024-10-17T09:45:18.641Z","updated_at":"2025-06-30T21:04:52.519Z","avatar_url":"https://github.com/kazu69.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# export-context\n\n![export-context](media/export-context.png)\n\n![](https://badge.fury.io/js/export-context.png)\n[![Build Status](https://travis-ci.org/kazu69/export-context.svg?branch=master)](https://travis-ci.org/kazu69/export-context)\n\n\u003e A method that has not been export can be run via the context.\n\u003e It will be able to unit test of unexport methods.\n\u003e Further, if necessary of dom can test by creating a document in global.\n\u003e Esnext code is transpile using the babel.\n\n## install\n\n```sh\nnpm install export-context --save-dev\n\n# or if using yarn\n\nyarn\n```\n\n## setup\n\n```js\nimport ExportContext from 'export-context';\n\n// configure option\nconst options = {\n    basePath: './',\n    babel: {\n        presets: ['latest'],\n        plugins: ['transform-runtime']\n    },\n    dom: true,\n    html: '\u003cdiv class=\"box\"\u003eexample\u003c/div\u003e',\n    vm: {\n        filename: \u003cstring\u003e,\n        lineOffset: \u003cnumber\u003e,\n        columnOffset: \u003cnumber\u003e,\n        displayErrors: \u003cboolean\u003e,\n        timeout: \u003cnumber\u003e,\n        breakOnSigint: \u003cboolean\u003e\n    }\n};\n\nconst modules = {\n    '_': 'lodash',\n    '$': 'jquery'\n};\n\nconst html = '\u003cspan class=\"comment\"\u003eexample commnet\u003c/span\u003e';\n\nconst exportContext = new ExportContext;\n\n// add dependent modules setting\nexportContext.addModules(modules);\n\n// add html code\nexportContext.addHtml(html);\n\n// get context\nconst ctx = exportContext.run('TARGET/FILE/PATH.js', options);\n\n// ctx has unexported method\n// ... some code ...\n\n// clear sandbox dom settings\nexportContext.clear()\n```\n\n\nIf the environment variable ```NODE_ENV``` is specified,\nit is reflected in the global variable and window object\n\n```js\n// set process.env.NODE_ENV = 'test'\n\nglobal.NODE_ENV // =\u003e test\nwindow.NODE_ENV // =\u003e test\n```\n\n## API\n\n### setFilepath(filePath = '')\n\nSet default load file path\n\n### addModules(modules = {}, sandbox = {})\n\nAdd the module to require at the time of context run.\n\n### addHtml(html = '')\n\nAdd the html to the context that you want to run.\n\n### clear()\n\nRemove the dom in the global from the execution context.\n\n### run(filePath = '', options = {})\n\nRun the contents of the passed file path. You can have the option, if necessary.\nExecuted context will be returned.\nThe options are as follows.\n\nIf already in the path has been set (using the ```setfilePath()```), ```run(options)``` method can be performed only in the only option.\n\n#### Options\n\n##### basePath\n\nSpecify the directory to be a base to load the file to be executed.\n(default: Projectroot).\n\n##### babel\n\nCode using esnext will run transformer pile in the babel.\nYou can set the options to be passed to the babel.\n(default: null)\n\n##### dom\n\nIf you run the code using DOM, please be true to this option.\nTo provide the necessary properties to global, you will be able to use the dom api.\n(default: null)\n\n##### html\n\nIf you want to set a pre-html adds html.\n(default: null)\n\n## example\n\nsee at below.\n\n- [using jquery with dom example](example/using-jquery)\n- [using esnext example](example/esnext)\n- [using ava example](example/using-ava)\n- [using tape example](example/using-tape)\n- [using mocha chai example](example/using-mocha-chai)\n\n## License\n\n[MIT License](http://en.wikipedia.org/wiki/MIT_License)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazu69%2Fexport-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkazu69%2Fexport-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazu69%2Fexport-context/lists"}