Skip to content

Commit

Permalink
Fix test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulioRandall committed Apr 28, 2024
1 parent 99a75bf commit 4880b33
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"devDependencies": {
"@nodelib/fs.walk": "2.0.0",
"jest": "29.7.0",
"prettier": "3.2.5"
"prettier": "3.2.5",
"upath": "2.0.1"
}
}
59 changes: 31 additions & 28 deletions src/parser.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import path from 'path'
import upath from 'upath'
import { parse, newNodeRegExp } from './parser'

const testdataDir = './src/testdata'

const createSvelteFilePath = (filename) => {
return `${testdataDir}/files/${filename}.svelte`
return upath.join(`${testdataDir}/files/${filename}.svelte`)
}

const generateFileFields = (file) => {
return {
name: upath.basename(file),
relPath: upath.join(file),
absPath: upath.resolve(file),
}
}

const parseToUnix = (f) => {
return parse(f).map((m) => {
m.relPath = upath.toUnix(m.relPath)
m.absPath = upath.toUnix(m.absPath)
return m
})
}

describe('p21', () => {
Expand Down Expand Up @@ -83,9 +99,7 @@ describe('p21', () => {

expect(metadata).toEqual([
{
name: path.basename(file),
relPath: file,
absPath: path.resolve(file),
...generateFileFields(file),
nodes: {
artist: 'Rhapsody of Fire',
},
Expand All @@ -99,9 +113,7 @@ describe('p21', () => {

expect(metadata).toEqual([
{
name: path.basename(file),
relPath: file,
absPath: path.resolve(file),
...generateFileFields(file),
nodes: {
artist: 'Rhapsody of Fire',
},
Expand All @@ -115,9 +127,7 @@ describe('p21', () => {

expect(metadata).toEqual([
{
name: path.basename(file),
relPath: file,
absPath: path.resolve(file),
...generateFileFields(file),
nodes: {
artist: 'Rhapsody of Fire',
album: 'From Chaos to Eternity',
Expand All @@ -133,9 +143,7 @@ describe('p21', () => {

expect(metadata).toEqual([
{
name: path.basename(file),
relPath: file,
absPath: path.resolve(file),
...generateFileFields(file),
nodes: {
bands: {
artist: 'Rhapsody of Fire',
Expand All @@ -151,9 +159,7 @@ describe('p21', () => {

expect(metadata).toEqual([
{
name: path.basename(file),
relPath: file,
absPath: path.resolve(file),
...generateFileFields(file),
nodes: {
music: {
bands: {
Expand All @@ -171,9 +177,7 @@ describe('p21', () => {

expect(metadata).toEqual([
{
name: path.basename(file),
relPath: file,
absPath: path.resolve(file),
...generateFileFields(file),
nodes: {
type: 'Music',
music: {
Expand All @@ -190,21 +194,22 @@ describe('p21', () => {
})

test('Parses directory', () => {
const metadata = parse(`${testdataDir}/dir`)
const dir = upath.join(`${testdataDir}/dir`)
const metadata = parse(dir)

expect(metadata).toEqual([
{
name: 'BandOne.svelte',
relPath: `${testdataDir}/dir/BandOne.svelte`,
absPath: path.resolve(`${testdataDir}/dir/BandOne.svelte`),
relPath: upath.join(`${testdataDir}/dir/BandOne.svelte`),
absPath: upath.resolve(`${testdataDir}/dir/BandOne.svelte`),
nodes: {
artist: 'Rhapsody of Fire',
},
},
{
name: 'BandTwo.svelte',
relPath: `${testdataDir}/dir/BandTwo.svelte`,
absPath: path.resolve(`${testdataDir}/dir/BandTwo.svelte`),
relPath: upath.join(`${testdataDir}/dir/BandTwo.svelte`),
absPath: upath.resolve(`${testdataDir}/dir/BandTwo.svelte`),
nodes: {
artist: 'Children of Bodom',
},
Expand All @@ -220,9 +225,7 @@ describe('p21', () => {

expect(metadata).toEqual([
{
name: path.basename(file),
relPath: file,
absPath: path.resolve(file),
...generateFileFields(file),
nodes: {
artist: 'Rhapsody of Fire',
},
Expand Down

0 comments on commit 4880b33

Please sign in to comment.