Unverified Commit efb0f265 authored by Aral's ThinkPad's avatar Aral's ThinkPad
Browse files

Fixed windows bug; removed hardcoded test paths

parent 3820fcd9
......@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [3.0.1] - 2020-09-02
### Fixed
- Now works on Windows 10 also.
- Fixed hardcoded paths in tests.
## [3.0.0] - 2020-08-31
### Added
......
......@@ -29,10 +29,13 @@ function routes (directory, directoryRoot = null) {
//
// File.
//
let routeCallbackFilePath = path.resolve(path.join(directory, file.name))
let routeUrlPath = path.join(directory.replace(directoryRoot, ''), file.name)
routeUrlPath = routeUrlPath.replace(/\/?index(.*?)\.js$/, '$1')
// Note: the regexp is written so that it will strip the leading slash properly
// ===== on both Linux-style and Windows environments.
routeUrlPath = routeUrlPath.replace(/\/?\\?index(.*?)\.js$/, '$1')
routeUrlPath = routeUrlPath.replace('.js', '')
routeUrlPath = routeUrlPath.replace(/\/$/, '')
......
{
"name": "@small-tech/web-routes-from-files",
"version": "2.0.0",
"version": "3.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "@small-tech/web-routes-from-files",
"version": "3.0.0",
"version": "3.0.1",
"description": "Recursively traverses a given directory structure and uses convention to create a list of web route objects that map url paths to JavaScript callback files.",
"keywords": [
"files",
......
......@@ -5,39 +5,40 @@ const test = require('tape')
test('routes', t => {
t.plan(12)
const actualRoutes = getRoutes(path.join('example', '.routes'))
const exampleRoutesPath = path.join('example', '.routes')
const actualRoutes = getRoutes(exampleRoutesPath)
const expectedRoutes = [
{
path: '/',
callback: '/home/aral/small-tech/site.js/lib/web-routes-from-files/example/.routes/index.js'
callback: 'index.js'
},
{
path: '/my-folder',
callback: '/home/aral/small-tech/site.js/lib/web-routes-from-files/example/.routes/my-folder/index.js'
callback: path.join('my-folder', 'index.js')
},
{
path: '/my-folder/other',
callback: '/home/aral/small-tech/site.js/lib/web-routes-from-files/example/.routes/my-folder/other.js'
callback: path.join('my-folder', 'other.js')
},
{
path: '/neat',
callback: '/home/aral/small-tech/site.js/lib/web-routes-from-files/example/.routes/neat.js'
callback: 'neat.js'
},
{
path: '/person/:personId/book/:bookId',
callback: '/home/aral/small-tech/site.js/lib/web-routes-from-files/example/.routes/person/index_personId__book_bookId.js'
callback: path.join('person', 'index_personId__book_bookId.js')
},
{
path: '/rabbit/:rabbitName',
callback: '/home/aral/small-tech/site.js/lib/web-routes-from-files/example/.routes/rabbit_rabbitName.js'
callback: 'rabbit_rabbitName.js'
}
]
expectedRoutes.forEach((expectedRoute, index) => {
const actualRoute = actualRoutes[index]
t.strictEquals(actualRoute.path, expectedRoute.path, `Route #${index}: route is correct.`)
t.strictEquals(actualRoute.callback, expectedRoute.callback, `Route #${index}: callback path is correct.`)
t.strictEquals(actualRoute.callback, path.join(path.resolve(exampleRoutesPath), expectedRoute.callback), `Route #${index}: callback path is correct.`)
})
t.end()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment