mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
WIP: fixing tests
This commit is contained in:
1 parent
8eaec839d3
commit
2bdb804f24
10 files changed
+49
-29
No files matched your search
@@ -6,6 +6,7 @@
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc && node post-build-script.js"
|
||||
"build": "tsc && node post-build-script.js",
|
||||
"test": "yarn build && jest"
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { basename } from './utils.js'
|
||||
|
||||
export default class File {
|
||||
constructor({ path, type, discovered }) {
|
||||
this.path = path.trimEnd('/')
|
||||
this.name = basename(path)
|
||||
this.type = type
|
||||
this.discovered = discovered
|
||||
}
|
||||
|
||||
isDirectory() {
|
||||
return this.type === 'folder'
|
||||
}
|
||||
|
||||
contains(file) {
|
||||
if (!this.isDirectory()) return false
|
||||
if (this.path === file.path) return true
|
||||
const parentPath = this.path.endsWith('/') ? this.path : `${this.path}/`
|
||||
return file.path.startsWith(parentPath)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import File from './file.js'
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
|
||||
import File from './file'
|
||||
|
||||
describe('File', () => {
|
||||
let file
|
||||
@@ -0,0 +1,33 @@
|
||||
/* eslint-disable lines-between-class-members */
|
||||
import { basename } from './utils'
|
||||
|
||||
interface FileObject {
|
||||
path: string
|
||||
type: string
|
||||
discovered: boolean
|
||||
}
|
||||
|
||||
export default class File implements FileObject {
|
||||
path: string
|
||||
name: string
|
||||
type: string
|
||||
discovered: boolean
|
||||
|
||||
constructor(obj: FileObject) {
|
||||
this.path = obj.path.trimEnd()
|
||||
this.name = basename(obj.path)
|
||||
this.type = obj.type
|
||||
this.discovered = obj.discovered
|
||||
}
|
||||
|
||||
isDirectory() {
|
||||
return this.type === 'folder'
|
||||
}
|
||||
|
||||
contains(file: FileObject) {
|
||||
if (!this.isDirectory()) return false
|
||||
if (this.path === file.path) return true
|
||||
const parentPath = this.path.endsWith('/') ? this.path : `${this.path}/`
|
||||
return file.path.startsWith(parentPath)
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import FileGraph from './fileGraph.js'
|
||||
import FileNode from './fileNode.js'
|
||||
import FileGraph from './fileGraph'
|
||||
import FileNode from './fileNode'
|
||||
|
||||
describe('FileGraph', () => {
|
||||
let root
|
||||
@@ -1,4 +1,4 @@
|
||||
import File from './file.js'
|
||||
import File from './file'
|
||||
import {
|
||||
DuplicateItemError,
|
||||
ParentNotExistsError,
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { DuplicateItemError, ParentNotExistsError } from './errors'
|
||||
import FileNode from './fileNode.js'
|
||||
import FileNode from './fileNode'
|
||||
|
||||
function createNodeFromFiles(files) {
|
||||
const node = new FileNode(files[0])
|
||||
@@ -1,3 +1,3 @@
|
||||
export { default as File } from './file.js'
|
||||
export { default as File } from './file'
|
||||
export { default as FileNode } from './fileNode.js'
|
||||
export { default as FileGraph } from './fileGraph.js'
|
||||
Reference in new issue
Block a user