Skip to content

Commit

Permalink
test: remove sfc snapshot, move other tests to snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
hannoeru committed May 12, 2021
1 parent a59e5ff commit d42d839
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 328 deletions.
16 changes: 16 additions & 0 deletions test/__snapshots__/files.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Get files Pages file: page files 1`] = `
Array [
"[...all].vue",
"[sensor]/current.vue",
"[userId].vue",
"about.vue",
"about/index.vue",
"blog/[id].vue",
"blog/index.vue",
"blog/today/index.vue",
"components.vue",
"index.vue",
]
`;
27 changes: 27 additions & 0 deletions test/__snapshots__/options.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Options resolve: resolved options 1`] = `
Object {
"exclude": Array [],
"extensions": Array [
"vue",
"js",
],
"extensionsRE": /\\\\\\.\\(vue\\|js\\)\\$/,
"importMode": "async",
"nuxtStyle": false,
"pagesDir": Array [
"src/pages",
],
"pagesDirOptions": Array [
Object {
"baseRoute": "",
"dir": "src/pages",
},
],
"react": false,
"replaceSquareBrackets": false,
"routeBlockLang": "json5",
"syncIndex": true,
}
`;
303 changes: 4 additions & 299 deletions test/__snapshots__/parser.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,305 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Parser SFC 1`] = `
exports[`Parser custom block: custom block 1`] = `
Object {
"cssVars": Array [],
"customBlocks": Array [
Object {
"attrs": Object {},
"content": "
{
meta: {
requiresAuth: false,
},
name: 'name-override',
}
",
"loc": Object {
"end": Object {
"column": 1,
"line": 21,
"offset": 230,
},
"source": "
{
meta: {
requiresAuth: false,
},
name: 'name-override',
}
",
"start": Object {
"column": 8,
"line": 14,
"offset": 160,
},
},
"map": Object {
"file": "anonymous.vue",
"mappings": ";;;;;;;;;;;;;;AAcA;EACE,CAAC,CAAC,CAAC,CAAC,EAAE;IACJ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;EACrB,CAAC;EACD,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB",
"names": Array [],
"sourceRoot": "",
"sources": Array [
"anonymous.vue",
],
"sourcesContent": Array [
"<script setup lang=\\"ts\\">
import { defineProps } from 'vue'
defineProps({
id: String,
})
</script>
<template>
blog/[id].vue: {{ id }}
</template>
<route>
{
meta: {
requiresAuth: false,
},
name: 'name-override',
}
</route>
",
],
"version": 3,
},
"type": "route",
},
],
"filename": "anonymous.vue",
"script": null,
"scriptSetup": Object {
"attrs": Object {
"lang": "ts",
"setup": true,
},
"content": "
import { defineProps } from 'vue'
defineProps({
id: String,
})
",
"lang": "ts",
"loc": Object {
"end": Object {
"column": 1,
"line": 8,
"offset": 92,
},
"source": "
import { defineProps } from 'vue'
defineProps({
id: String,
})
",
"start": Object {
"column": 25,
"line": 1,
"offset": 24,
},
},
"setup": true,
"type": "script",
},
"slotted": false,
"source": "<script setup lang=\\"ts\\">
import { defineProps } from 'vue'
defineProps({
id: String,
})
</script>
<template>
blog/[id].vue: {{ id }}
</template>
<route>
{
meta: {
requiresAuth: false,
},
name: 'name-override',
}
</route>
",
"styles": Array [],
"template": Object {
"ast": Object {
"children": Array [
Object {
"content": " blog/[id].vue: ",
"loc": Object {
"end": Object {
"column": 18,
"line": 11,
"offset": 131,
},
"source": "
blog/[id].vue: ",
"start": Object {
"column": 11,
"line": 10,
"offset": 113,
},
},
"type": 2,
},
Object {
"content": Object {
"constType": 0,
"content": "id",
"isStatic": false,
"loc": Object {
"end": Object {
"column": 23,
"line": 11,
"offset": 136,
},
"source": "id",
"start": Object {
"column": 21,
"line": 11,
"offset": 134,
},
},
"type": 4,
},
"loc": Object {
"end": Object {
"column": 26,
"line": 11,
"offset": 139,
},
"source": "{{ id }}",
"start": Object {
"column": 18,
"line": 11,
"offset": 131,
},
},
"type": 5,
},
Object {
"content": "
",
"loc": Object {
"end": Object {
"column": 1,
"line": 12,
"offset": 140,
},
"source": "
",
"start": Object {
"column": 26,
"line": 11,
"offset": 139,
},
},
"type": 2,
},
],
"codegenNode": undefined,
"isSelfClosing": false,
"loc": Object {
"end": Object {
"column": 12,
"line": 12,
"offset": 151,
},
"source": "<template>
blog/[id].vue: {{ id }}
</template>",
"start": Object {
"column": 1,
"line": 10,
"offset": 103,
},
},
"ns": 0,
"props": Array [],
"tag": "template",
"tagType": 0,
"type": 1,
},
"attrs": Object {},
"content": "
blog/[id].vue: {{ id }}
",
"loc": Object {
"end": Object {
"column": 1,
"line": 12,
"offset": 140,
},
"source": "
blog/[id].vue: {{ id }}
",
"start": Object {
"column": 11,
"line": 10,
"offset": 113,
},
},
"map": Object {
"file": "anonymous.vue",
"mappings": ";EAUE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC",
"names": Array [],
"sourceRoot": "",
"sources": Array [
"anonymous.vue",
],
"sourcesContent": Array [
"<script setup lang=\\"ts\\">
import { defineProps } from 'vue'
defineProps({
id: String,
})
</script>
<template>
blog/[id].vue: {{ id }}
</template>
<route>
{
meta: {
requiresAuth: false,
},
name: 'name-override',
}
</route>
",
],
"version": 3,
},
"type": "template",
"meta": Object {
"requiresAuth": false,
},
"name": "name-override",
}
`;
3 changes: 1 addition & 2 deletions test/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { getPageFiles } from '../src/files'

const options = resolveOptions({})
const testPagesDir = resolve('test/assets/pages')
const expectFiles = ['[...all].vue', 'about.vue', 'components.vue', 'index.vue', '[sensor]/current.vue', 'about/index.vue', 'blog/[id].vue', 'blog/index.vue', 'blog/today/index.vue', '[userId].vue']

describe('Get files', () => {
test('Pages file', async() => {
const files = await getPageFiles(testPagesDir, options)
expect(files.sort()).toEqual(expectFiles.sort())
expect(files.sort()).toMatchSnapshot('page files')
})
})
18 changes: 2 additions & 16 deletions test/options.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { resolveOptions } from '../src/options'

const resolvedOptions = {
routeBlockLang: 'json5',
root: process.cwd(),
pagesDir: ['src/pages'],
pagesDirOptions: [{ dir: 'src/pages', baseRoute: '' }],
extensions: ['vue', 'js'],
extensionsRE: /\.(vue|js)$/,
importMode: 'async',
nuxtStyle: false,
exclude: [],
syncIndex: true,
react: false,
replaceSquareBrackets: false,
}

describe('Options', () => {
test('resolve', () => {
const options = resolveOptions({})
expect(options).toStrictEqual(resolvedOptions)
delete options.root
expect(options).toMatchSnapshot('resolved options')
})
})
Loading

0 comments on commit d42d839

Please sign in to comment.