Skip to content

Commit

Permalink
Revert "fix: updated nuekit JS errors tests"
Browse files Browse the repository at this point in the history
This reverts commit b50cca2.
  • Loading branch information
alexpricedev committed Jan 26, 2025
1 parent b50cca2 commit e1c9e9f
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions packages/nuekit/test/nuekit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ expect.extend({ toMatchPath })
// temporary directory
const root = '_test'


// setup and teardown
beforeEach(async () => {
await fs.rm(root, { recursive: true, force: true })
Expand Down Expand Up @@ -86,6 +87,7 @@ test('environment', async () => {
expect(site.port).toBe(8080)
})


// NOTE: undocumented feature for the next release
const MODEL = `
export default async function (opts) {
Expand Down Expand Up @@ -118,6 +120,7 @@ test('server_model', async () => {
expect(namespace).toBe('test')
})


const CUSTOM_TAGS = `
export default async function (opts) {
return {
Expand All @@ -137,6 +140,7 @@ test('custom tags', async () => {
expect(tags).toHaveProperty('line-graph')
})


test('page styles', async () => {
await write('site.yaml', 'globals: [globals]')

Expand All @@ -152,24 +156,26 @@ test('page styles', async () => {
expect(arr2.length).toBe(3)
})


test('root styles', async () => {
const kit = await getKit()
await write('globals/bar.css')
await write('home.css')
await write('index.md')
const { assets } = await kit.getPageData('index.md')
expect(assets.styles).toEqual(['/home.css'])
expect(assets.styles).toEqual(["/home.css"])
})


test('include/exclude data', async () => {
await write('site.yaml', 'include: [a]\nexclude: [a]')
await write('blog/app.yaml', 'include: [b]\nexclude: [b]')
await write('blog/index.md', '---\ninclude: [c]\n---\n')
const kit = await getKit()
const data = await kit.getPageData('blog/index.md')

expect(data.include).toEqual(['a', 'b', 'c'])
expect(data.exclude).toEqual(['a', 'b'])
expect(data.include).toEqual(["a", "b", "c"])
expect(data.exclude).toEqual(["a", "b"])
})

test('asset include/exclude', async () => {
Expand All @@ -185,10 +191,11 @@ test('asset include/exclude', async () => {
const kit = await getKit()
const { assets } = await kit.getPageData('blog/index.md')

expect(assets.styles).toEqual(['/global/global.css', '/lib/boom.css', '/lib/zoo.css'])
expect(assets.styles).toEqual(["/global/global.css", "/lib/boom.css", "/lib/zoo.css"])
// expect(data.components).toEqual([ "/global/kama.js", "/lib/zoo.css" ])
})


test('get data', async () => {
await write('site.yaml', 'foo: 1')

Expand All @@ -200,14 +207,15 @@ test('get data', async () => {
expect(data).toMatchObject({ foo: 1, bar: 1, baz: 1 })
})


test('content collection', async () => {
await write('blog/first-a.md', '# First')
await write('blog/first-b.md', createFront('Second', '2025-01-04'))
await write('blog/nested/hey1.md', createFront('Third', '2025-01-02'))
await write('blog/nested/hey2.md', createFront('Fourth', '2025-01-03'))

// these should be excluded
await write('blog/functions/contact-us.md', 'my secret notes')
await write('blog/functions/contact-us.md', "my secret notes")
await write('blog/.item6.md', createFront('Sixth', '2025-01-03'))
await write('blog/_item7.md', createFront('Seventh', '2025-01-03'))

Expand All @@ -223,7 +231,7 @@ test('content collection', async () => {
expect(coll[2].slug).toBe('hey2.html')

// page metadata
expect(coll[0]).toMatchObject({ title: 'First', slug: 'first-a.html', basedir: 'blog' })
expect(coll[0]).toMatchObject({ title: "First", slug: "first-a.html", basedir: "blog" })
})

test('basic page generation', async () => {
Expand All @@ -241,6 +249,7 @@ test('basic page generation', async () => {
expect(html).toInclude('<p>World</p>')
})


test('simple custom tag', async () => {
await write('layout.html', '<a @name="test">Hey</a>')
await write('index.md', '[test]')
Expand All @@ -257,7 +266,11 @@ test('custom tag with <slot/>', async () => {
<slot/>
</div>
`
const MD = ['[test]', ' ### World', ' { slug }']
const MD = [
'[test]',
' ### World',
' { slug }',
]

await write('components.html', HTML)
await write('index.md', MD.join('\n'))
Expand All @@ -269,6 +282,7 @@ test('custom tag with <slot/>', async () => {
expect(html).toInclude('<p>index.html</p>')
})


test('layout components', async () => {
const site = await getSite()

Expand All @@ -291,15 +305,13 @@ test('layout components', async () => {
expect(comps3[0].name).toBe('c')
})


test('page layout', async () => {
await write(
'layout.html',
`
await write('layout.html', `
<header>Header</header>
<aside>Aside</aside>
<aside @name="beside">Beside</aside>
`
)
`)
await write('site.yaml', 'aside: false')
await write('index.md', '# Hey')

Expand All @@ -312,6 +324,7 @@ test('page layout', async () => {
expect(html).toInclude('<aside>Beside</aside>')
})


test('getRequestPaths', async () => {
await write('index.md')
const site = await getSite()
Expand All @@ -330,6 +343,7 @@ test('getRequestPaths', async () => {
expect(await site.getRequestPaths('/admin/readme.html')).toMatchObject({ path: '404.html' })
})


test('inline CSS', async () => {
const kit = await getKit()
await write('inline/style.css', 'body { margin: 0 }')
Expand All @@ -342,12 +356,10 @@ test('inline CSS', async () => {
expect(html).toInclude('margin:')
})


test('line endings', async () => {
const kit = await getKit()
await write(
'index.md',
'---\ntitle: Page title\rhero: img/image.png\r\n---\r\n\r# Hello\r\n\rWorld'
)
await write('index.md', '---\ntitle: Page title\rhero: img/image.png\r\n---\r\n\r# Hello\r\n\rWorld')
const data = await kit.getPageData('index.md')
expect(data.title).toBe('Page title')
expect(data.hero).toBe('img/image.png')
Expand All @@ -368,10 +380,11 @@ test('page assets', async () => {
const kit = await getKit()
const { assets } = await kit.getPageData('blog/index.md')

expect(assets.components).toEqual(['/blog/comp.js', '/lib/video.js'])
expect(assets.components).toEqual(["/blog/comp.js", "/lib/video.js"])
expect(assets.scripts.length).toEqual(4)
})


test('single-page app index', async () => {
await write('index.html', '<test/>')
const kit = await getKit()
Expand All @@ -382,6 +395,7 @@ test('single-page app index', async () => {
expect(html).toInclude('<test custom="test">')
})


test('bundle', async () => {
await write('a.ts', 'export const foo = 30')
await write('b.ts', 'import { foo } from "./a.js"; const bar = 10 + foo')
Expand All @@ -401,27 +415,24 @@ test('JS errors', async () => {
await write('a.js', code)
const opts = { path: `./${root}/a.js`, outdir: root, silent: true }

let err = null
try {
await buildJS(opts)
} catch (e) {
err = e
// console.info(e)
expect(e.lineText).toBe(code)
}

expect(err.lineText).toBe(code)

let err2 = null
try {
await buildJS({ ...opts, esbuild: true })
} catch (e) {
err2 = e
expect(e.lineText).toBe(code)
}

expect(err2.lineText).toBe(code)
})


test('the project was started for the first time', async () => {
await write('site.yaml', 'port: 8808')
await write('site.yaml', 'port: 9090')
await write('globals/bar.css')
await write('home.css')
await write('index.md')
Expand Down

0 comments on commit e1c9e9f

Please sign in to comment.