{"id":25837259,"url":"https://github.com/devtin/jest-parser","last_synced_at":"2025-06-24T15:40:56.750Z","repository":{"id":57280412,"uuid":"345146983","full_name":"devtin/jest-parser","owner":"devtin","description":"parses jest files","archived":false,"fork":false,"pushed_at":"2022-08-19T13:18:42.000Z","size":94,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-04T12:17:52.219Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/devtin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-06T16:57:48.000Z","updated_at":"2024-05-23T08:13:21.000Z","dependencies_parsed_at":"2022-09-19T17:03:13.816Z","dependency_job_id":null,"html_url":"https://github.com/devtin/jest-parser","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/devtin/jest-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devtin%2Fjest-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devtin%2Fjest-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devtin%2Fjest-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devtin%2Fjest-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devtin","download_url":"https://codeload.github.com/devtin/jest-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devtin%2Fjest-parser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261705430,"owners_count":23197367,"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":[],"created_at":"2025-03-01T02:48:05.542Z","updated_at":"2025-06-24T15:40:56.707Z","avatar_url":"https://github.com/devtin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv\u003e\u003ch1\u003ejest-parser\u003c/h1\u003e\u003c/div\u003e\n\n\u003cp\u003e\n    \u003ca href=\"https://www.npmjs.com/package/jest-parser\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/jest-parser.svg\" alt=\"Version\"\u003e\u003c/a\u003e\n\u003ca href=\"http://opensource.org/licenses\" target=\"_blank\"\u003e\u003cimg src=\"http://img.shields.io/badge/License-MIT-brightgreen.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n    Parses jest tests into an object\n\u003c/p\u003e\n\n## Manifesto\n\nSince nothing describes better what a software does than its tests, in order to make easy the documentation process, I\nwant to be able to parse the content of a jest file. \n\nMind this library is RegExp-based. See [disclaimer](#disclaimer) below.\n\n## Installation\n\n```sh\n$ npm i jest-parser --save\n# or\n$ yarn add jest-parser\n```\n\n## Features\n\n- [Parses jest syntax](#parses-jest-syntax)\n\n\n\u003ca name=\"loads-entities-from-directory\"\u003e\u003c/a\u003e\n\n## Parses jest syntax\n\nTake the following jest file:\n\n```js\ndescribe('Some describe title 1', () =\u003e {\n    // some code 1\n    /* eslint-disable-next-line */\n    describe.only('Nested describe 1', () =\u003e {\n        // some setup\n        // some more setup\n\n        it('does this and that', () =\u003e {\n            // code of what it does\n            expect(true).toBeTruthy()\n        })\n    })\n})\n\ndescribe('Some describe title 2', () =\u003e {\n    // some code 2\n})\n\ndescribe('Some describe title 3', () =\u003e {\n    // some code 3\n})\n```\n...and the following script:\n\n```js\nconst { parse } = require('jest-parser')\nconst { readFileSync } = require('fs')\n\nconsole.log(parse('Some jest file', readFileSync('jest-test.js').toString()))\n```\nwould produce the following output:\n\n```json\n{\n  \"title\": \"Some jest file\",\n  \"describe\": [\n    {\n      \"title\": \"Some describe title 1\",\n      // entire file code\n      \"code\": \"// some code 1\\n/* eslint-disable-next-line */\\ndescribe.only('Nested describe 1', () =\u003e {\\n    // some setup\\n    // some more setup\\n\\n    it('does this and that', () =\u003e {\\n        // code of what it does\\n        expect(true).toBeTruthy()\\n    })\\n})\",\n      \"start\": 0,\n      \"end\": 12,\n      \"describe\": [\n        {\n          \"title\": \"Nested describe 1\",\n          // piece of code within \"Nested describe 1\"\n          \"code\": \"// some setup\\n// some more setup\\n\\nit('does this and that', () =\u003e {\\n    // code of what it does\\n    expect(true).toBeTruthy()\\n})\",\n          // position where \"Nested describe 1\" starts in parent's code\n          \"start\": 2,\n          // position where \"Nested describe 1\" ends in parent's code\n          \"end\": 10,\n          \"flag\": \"only\", // flags the test scenario might have (only, skip, todo...)\n          \"describe\": [],\n          \"test\": [],\n          \"it\": [\n            {\n              \"title\": \"does this and that\",\n              \"code\": \"// code of what it does\\nexpect(true).toBeTruthy()\",\n              \"start\": 3,\n              \"end\": 6,\n              \"describe\": [],\n              \"test\": [],\n              \"it\": []\n            }\n          ]\n        }\n      ],\n      \"test\": [],\n      \"it\": []\n    },\n    {\n      \"title\": \"Some describe title 2\",\n      \"code\": \"// some code 2\",\n      \"start\": 14,\n      \"end\": 16,\n      \"describe\": [],\n      \"test\": [],\n      \"it\": []\n    },\n    {\n      \"title\": \"Some describe title 3\",\n      \"code\": \"// some code 3\",\n      \"start\": 18,\n      \"end\": 20,\n      \"describe\": [],\n      \"test\": [],\n      \"it\": []\n    }\n  ],\n  \"test\": [],\n  \"it\": []\n}\n```\n\n## Disclaimer \n\nMind this library is RegExp-based (not AST-based). That said, it might not work well using funky syntax.\n\nOne known scenario it won't work is a oneliner test (see discussion [here](https://github.com/devtin/jest-parser/pull/1)):\n\n```js\n// none of this would work\nit('one line explicit-return arrow function', () =\u003e { return Promise.resolve(true) })\nit('one line implicit-return arrow function', () =\u003e Promise.resolve(true))\nit('multiline implicit-return arrow function', () =\u003e\n    Promise.resolve(true)\n)\n```\n\n* * *\n\n### License\n\n[MIT](https://opensource.org/licenses/MIT)\n\n\u0026copy; 2021-present Martin Rafael Gonzalez \u003ctin@devtin.io\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevtin%2Fjest-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevtin%2Fjest-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevtin%2Fjest-parser/lists"}