Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tinvaan committed May 27, 2024
1 parent 85917f9 commit 4d90f8f
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions provider/techstack/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@

import path from 'path'
import { describe, expect, test } from 'vitest'
import {type AnnotationsResult, type CapabilitiesResult} from '@opencodegraph/provider'
import type {
AnnotationsResult,
AnnotationsParams,

Check failure on line 6 in provider/techstack/index.test.ts

View workflow job for this annotation

GitHub Actions / build

This import is unused.
MetaParams,

Check failure on line 7 in provider/techstack/index.test.ts

View workflow job for this annotation

GitHub Actions / build

This import is unused.
MetaResult
} from '@openctx/provider'

import techstack, { type Settings } from './index'
import techstack, { type Settings } from './index.js'

describe('techstack', () => {
const SETTINGS: Settings = {
yaml: path.resolve(path.join(__dirname, './examples/mazure.yml'))
}

test('capabilities', () => {
const result = techstack.capabilities({}, SETTINGS)
test('meta', () => {
const result = techstack.meta({}, SETTINGS)

expect(result).toBeDefined()
expect(result).toStrictEqual<CapabilitiesResult>({
selector: [{ path: '**/*.js?(x)' }, { path: '**/*.ts?(x)' }]
expect(result).toStrictEqual<MetaResult>({
name: 'TechStack File',
selector: [{ path: '**/*.js?(x)' }, { path: '**/*.ts?(x)' }],
features: { mentions: false }
})
})

test('annotations', async () => {
let params = {
file: 'file:///a/b.ts',
uri: 'file:///a/b.ts',
content: `
import fs from 'fs'
Expand All @@ -30,15 +37,15 @@ fs.readFileSync('example.txt', 'utf-8)
}
let result = await techstack.annotations(params, SETTINGS)
expect(result).toBeDefined()
expect(result).toStrictEqual<AnnotationsResult>({ annotations: [], items: [] })
expect(result).toStrictEqual<AnnotationsResult>([])

SETTINGS.yaml = path.resolve(path.join(__dirname, './examples/stackshare.yml'))
result = await techstack.annotations(params, SETTINGS)
expect(result).toBeDefined()
expect(result).toStrictEqual<AnnotationsResult>({ annotations: [], items: [] })
expect(result).toStrictEqual<AnnotationsResult>([])

params = {
file: 'file:///c/d.ts',
uri: 'file:///c/d.ts',
content: `
var sass = require('node-sass');
sass.render({
Expand All @@ -54,9 +61,10 @@ var result = sass.renderSync({
}
result = await techstack.annotations(params, SETTINGS)
expect(result).toBeDefined()
expect(result.items[0].id).toEqual('1')
expect(result.annotations[0].item.id).toEqual('1')
expect(result.items[0].title).includes('npm Packages')
expect(result.length).toEqual(1)
expect(result[0].uri).toEqual(params.uri)
expect(result[0].item.title).includes('npm Packages')
expect(result[0].item.url).toEqual('https://www.npmjs.com/node-sass')

params.content = `
var sass = require('node-sass');
Expand All @@ -69,9 +77,12 @@ sass = require('node-sass') // unexpected import
`
result = await techstack.annotations(params, SETTINGS)
expect(result).toBeDefined()
expect(result.items[0].id).toEqual('1')
expect(result.annotations[0].item.id).toEqual('1')
expect(result.items[1].id).toEqual('7')
expect(result.annotations[1].item.id).toEqual('7')
expect(result.length).toEqual(2)

expect(result[0].range?.start.line).toEqual(1)
expect(result[0].range?.end.line).toEqual(1)

expect(result[1].range?.start.line).toEqual(7)
expect(result[1].range?.end.line).toEqual(7)
})
})

0 comments on commit 4d90f8f

Please sign in to comment.