|
| 1 | +import{join}from'path'; |
| 2 | + |
| 3 | +import{isWindows}from'../../../polyfills/system'; |
| 4 | + |
| 5 | +/** |
| 6 | + * set paths to tests as absolute paths |
| 7 | + *@param {string} dir |
| 8 | + *@param {string} name |
| 9 | + *@param {Tutorial.Config} config |
| 10 | + *@param {string} testPath |
| 11 | + *@returns string |
| 12 | + */ |
| 13 | +exportdefaultfunctionconfigPath({ |
| 14 | + dir, tutorial, testPath |
| 15 | +}):string{ |
| 16 | + |
| 17 | +if(isWindows){ |
| 18 | +// adjust paths for windows slashes |
| 19 | +testPath=testPath.split('/').join('\\'); |
| 20 | +} |
| 21 | + |
| 22 | +// adjust absolute file path |
| 23 | +if(tutorial.config.dir){ |
| 24 | +testPath=join(tutorial.config.dir,testPath); |
| 25 | +}else{ |
| 26 | +testPath=join(dir,'node_modules',tutorial.name,testPath); |
| 27 | +} |
| 28 | + |
| 29 | +if(tutorial.config.testSuffix){ |
| 30 | +// prevent repeat appending test suffix |
| 31 | +testPath+=tutorial.config.testSuffix; |
| 32 | +} |
| 33 | + |
| 34 | +returntestPath; |
| 35 | +} |
| 36 | +/** |
| 37 | + * loops over task tests and set paths to absolute paths |
| 38 | + *@param {string} dir |
| 39 | + *@param {string} name |
| 40 | + *@param {Tutorial.Config} config |
| 41 | + *@param {CR.Page[]} pages |
| 42 | + *@returns CR |
| 43 | + */ |
| 44 | +// export default function configPaths( |
| 45 | +// dir: string, name: string, config: Tutorial.Config, pages: CR.Page[] |
| 46 | +// ): CR.Page[] { |
| 47 | +// return pages.map((page: CR.Page): CR.Page => { |
| 48 | +// if (!page.tasks) { |
| 49 | +// page.tasks = []; |
| 50 | +// } |
| 51 | +// page.tasks.map((task: CR.Task): CR.Task => { |
| 52 | + |
| 53 | +// if (!task.tests) { return task; } |
| 54 | + |
| 55 | +// // change testPaths to use absolute URLs |
| 56 | +// task.tests = task.tests.map((testPath: string) => { |
| 57 | +// // add unique string to tests |
| 58 | +// if (typeof testPath === 'string') { |
| 59 | +// return configTestString(dir, name, config, testPath); |
| 60 | +// } else { |
| 61 | +// console.error('Invalid task test', testPath); |
| 62 | +// return 'ERROR'; |
| 63 | +// } |
| 64 | +// }); |
| 65 | +// return task; |
| 66 | +// }); |
| 67 | +// return page; |
| 68 | +// }); |
| 69 | +// } |