Skip to content

Commit

Permalink
fix: switch all paths to upath to fix tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTowles committed Sep 29, 2022
1 parent 1a6fe47 commit 6dbea01
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 163 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"default": "${currentFileDir}",
"description": "The destination to save image file. You can use variable ${currentFileDir} and ${projectRoot}. ${currentFileDir} will be replace by the path of directory that contain current editing file. ${projectRoot} will be replace by path of the project opened in vscode."
},

"pasteImage.defaultImageName": {
"type": "string",
"default": "yyyy-LL-mm-HH-mm-ss",
Expand All @@ -59,12 +58,12 @@
"pasteImage.imageUriPathPrefix": {
"type": "string",
"default": "",
"description": "The string prepend to the resolved image path. Can be used if you want to supply a custom domain to image url."
"description": "The string prepend to the resolved image upath. Can be used if you want to supply a custom domain to image url."
},
"pasteImage.imageUriPathSuffix": {
"type": "string",
"default": "",
"description": "The string append to the resolved image path. Can be used if you want to supply a custom params to image url."
"description": "The string append to the resolved image upath. Can be used if you want to supply a custom params to image url."
},
"pasteImage.encodePath": {
"type": "string",
Expand Down Expand Up @@ -126,7 +125,7 @@
"vscode:prepublish": "nr build",
"publish": "vsce publish --no-dependencies",
"pack": "vsce package --no-dependencies",
"test": "vitest",
"test": "vitest --reporter verbose",
"typecheck": "tsc --noEmit",
"release": "bumpp --commit --push --tag && nr publish",
"readme": "esno ./scripts/docs.ts"
Expand All @@ -143,6 +142,7 @@
"@types/luxon": "^3.0.1",
"@types/node": "^18.7.19",
"@types/vscode": "^1.71.0",
"@vitest/ui": "^0.23.4",
"@vscode/test-electron": "^2.1.5",
"bumpp": "^8.2.1",
"eslint": "^8.19.0",
Expand Down
36 changes: 34 additions & 2 deletions pnpm-lock.yaml

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

96 changes: 49 additions & 47 deletions src/configuration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import { Constants } from "./constants";
import { parseConfigurationToConfig, replacePathVariable } from "./configuration";
import path from 'path';
import * as upath from 'upath';
import { MockWorkspaceConfiguration } from './test/mockWorkspaceConfiguration';


Expand All @@ -27,11 +27,11 @@ describe('Configuration', () => {

it('replacePathVariable - no replacement done', () => {
const originalPath = `/dir1/dir2`
const editorFile = path.join(__dirname, 'test', 'test.md');
const editorFile = upath.join(__dirname, 'test', 'test.md');
const alteredValue = replacePathVariable({
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: __dirname,
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: __dirname,
})

// no replacement done
Expand All @@ -41,43 +41,43 @@ describe('Configuration', () => {

it('replacePathVariable - replace with edit file\'s folder', () => {
const originalPath = '${currentFileDir}'
const editorFile = path.join(__dirname, 'test', 'test.md');
const editorFile = upath.join(__dirname, 'test', 'test.md');
const alteredValue = replacePathVariable({
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: __dirname,
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: __dirname,
})

// should replace with folder of editor file
expect(alteredValue).toBe(path.dirname(editorFile));
expect(alteredValue).toBe(upath.dirname(editorFile));

})


it('replacePathVariable - replace with edit file\'s folder and append another folder', () => {
const originalPath = '${currentFileDir}/test2Folder'
const editorFile = path.join(__dirname, 'test', 'test.md');
const editorFile = upath.join(__dirname, 'test', 'test.md');
const alteredValue = replacePathVariable({
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: __dirname,
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: __dirname,
})

// should replace with folder of editor file and append another folder
const targetFolder = path.join(path.dirname(editorFile), 'test2Folder');
const targetFolder = upath.join(upath.dirname(editorFile), 'test2Folder');
expect(alteredValue).toBe(targetFolder);

})

it('replacePathVariable - replace with projectRoot', () => {
const originalPath = '${projectRoot}'
const editorFile = path.join(__dirname, 'test', 'test.md');
const editorFile = upath.join(__dirname, 'test', 'test.md');
const productRoot = __dirname;

const alteredValue = replacePathVariable({
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: productRoot,
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: productRoot,
})

// should replace with folder of editor file
Expand All @@ -86,13 +86,13 @@ describe('Configuration', () => {

it('replacePathVariable - replace with projectRoot', () => {
const originalPath = '${projectRoot}'
const editorFile = path.join(__dirname, 'test', 'test.md');
const editorFile = upath.join(__dirname, 'test', 'test.md');
const productRoot = __dirname;

const alteredValue = replacePathVariable({
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: productRoot,
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: productRoot,
})

// should replace with folder of editor file
Expand All @@ -102,55 +102,57 @@ describe('Configuration', () => {

it('replacePathVariable - replace with currentFileName', () => {
const originalPath = '${currentFileName}'
const editorFile = path.join(__dirname, 'test', 'test.md');
const editorFile = upath.join(__dirname, 'test', 'test.md');
const productRoot = __dirname;

const alteredValue = replacePathVariable({
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: productRoot,
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: productRoot,
})

// should replace with editor
expect(alteredValue).toBe(path.basename(editorFile));
expect(alteredValue).toBe(upath.basename(editorFile));
})



it('replacePathVariable - replace with currentFileNameWithoutExt', () => {
const originalPath = '${currentFileNameWithoutExt}'
const editorFile = path.join(__dirname, 'test', 'test.md');
const editorFile = upath.join(__dirname, 'test', 'test.md');
const productRoot = __dirname;

const alteredValue = replacePathVariable({
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: productRoot,
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: productRoot,
})

let ext = path.extname(editorFile);
let fileNameWithoutExt = path.basename(editorFile, ext);
let ext = upath.extname(editorFile);
let fileNameWithoutExt = upath.basename(editorFile, ext);

// should replace with editor filename without ext
expect(alteredValue).toBe(fileNameWithoutExt);
})

it('replacePathVariable - replace with projectRoot and currentFileNameWithoutExt', () => {
const originalPath = '${projectRoot}/${currentFileNameWithoutExt}.png'
const editorFile = path.join(__dirname, 'test', 'test.md');
const originalPath = upath.join('${projectRoot}', '${currentFileNameWithoutExt}.png');
const editorFile = upath.join(__dirname, 'test', 'test.md');
const productRoot = __dirname;


console.log({ originalPath, editorFile, productRoot });
const alteredValue = replacePathVariable({
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: productRoot,
pathStr: originalPath,
editorOpenFilePath: editorFile,
projectRootDirPath: productRoot,
})

let ext = path.extname(editorFile);
let fileNameWithoutExt = path.basename(editorFile, ext);
let ext = upath.extname(editorFile);
let fileNameWithoutExt = upath.basename(editorFile, ext);

// should replace with editor filename without ext
expect(alteredValue).toBe(path.join(productRoot, `${fileNameWithoutExt}.png`));

expect(alteredValue).toBe((upath.join(productRoot, `${fileNameWithoutExt}.png`)));
})


Expand Down

0 comments on commit 6dbea01

Please sign in to comment.