0.0.7 • Published 10 months ago

describe-ast-parser v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

describe-ast-parser

NPM npm

Parses jest code to AST and extract nodes with describe and test

Install

npm i describe-ast-parser

Usage

// test.spec.ts

describe('test.spec.ts', () => {
  test('test 1', () => {
    expect('Hello World').toBe('Hello World')
  })

  test('test 2', () => {
    expect(true).toBe(true)
  })
})
// index.ts

import { parse } from 'describe-ast-parser'
import { readFileSync } from 'fs'

console.log(parse(readFileSync('src/test.spec.ts', 'utf8')))
[
  {
    "type": "StringLiteral",
    "start": 9,
    "end": 23,
    "loc": {
      "start": {
        "line": 1,
        "column": 9,
        "index": 9
      },
      "end": {
        "line": 1,
        "column": 23,
        "index": 23
      }
    },
    "extra": {
      "rawValue": "test.spec.ts",
      "raw": "'test.spec.ts'"
    },
    "value": "test.spec.ts"
  },
  {
    "type": "StringLiteral",
    "start": 40,
    "end": 48,
    "loc": {
      "start": {
        "line": 2,
        "column": 7,
        "index": 40
      },
      "end": {
        "line": 2,
        "column": 15,
        "index": 48
      }
    },
    "extra": {
      "rawValue": "test 1",
      "raw": "'test 1'"
    },
    "value": "test 1"
  },
  {
    "type": "StringLiteral",
    "start": 117,
    "end": 125,
    "loc": {
      "start": {
        "line": 6,
        "column": 7,
        "index": 117
      },
      "end": {
        "line": 6,
        "column": 15,
        "index": 125
      }
    },
    "extra": {
      "rawValue": "test 2",
      "raw": "'test 2'"
    },
    "value": "test 2"
  }
]

License

This project is licensed MIT license.

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago