Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

index.js 1.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  1. const path = require('path')
  2. const dataDirectory = require('../../../lib/data-directory')
  3. const fixturesDir = path.join(__dirname, 'fixtures')
  4. describe('data-directory', () => {
  5. test('works', async () => {
  6. const data = await dataDirectory(fixturesDir)
  7. const expected = {
  8. bar: { another_markup_language: 'yes' },
  9. foo: { meaningOfLife: 42 },
  10. nested: { baz: 'I am markdown!' }
  11. }
  12. expect(data).toEqual(expected)
  13. })
  14. test('option: preprocess function', async () => {
  15. const preprocess = function (content) {
  16. return content.replace('markdown', 'MARKDOWN')
  17. }
  18. const data = await dataDirectory(fixturesDir, { preprocess })
  19. expect(data.nested.baz).toBe('I am MARKDOWN!')
  20. })
  21. test('option: extensions array', async () => {
  22. const extensions = ['.yaml', 'markdown']
  23. const data = await dataDirectory(fixturesDir, { extensions })
  24. expect('bar' in data).toBe(true)
  25. expect('foo' in data).toBe(false) // JSON file should be ignored
  26. })
  27. test('option: ignorePatterns', async () => {
  28. const ignorePatterns = []
  29. // README is ignored by default
  30. expect('README' in await dataDirectory(fixturesDir)).toBe(false)
  31. // README can be included by setting empty ignorePatterns array
  32. expect('README' in await dataDirectory(fixturesDir, { ignorePatterns })).toBe(true)
  33. })
  34. })
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...