88 */
99
1010import { default as assert , AssertionError } from "node:assert" ;
11+ import { join as pathJoin , isAbsolute as isAbsolutePath , dirname } from "node:path" ;
1112import util from "node:util" ;
1213import stableJsonStringify from "json-stable-stringify-without-jsonify" ;
1314import { ecmaFeaturesOverride , setEcmaVersion , ECMA_VERSION } from "../plugins/context.ts" ;
@@ -974,17 +975,25 @@ function lint(test: TestCase, plugin: Plugin): Diagnostic[] {
974975 // Get parse options
975976 const parseOptions = getParseOptions ( test ) ;
976977
977- // Determine filename .
978+ // Determine path .
978979 // If not provided, use default filename based on `parseOptions.lang`.
979- let { filename } = test ;
980+ let path : string ;
981+
982+ const { filename } = test ;
980983 if ( filename == null ) {
981984 let ext : string | undefined = parseOptions . lang ;
982985 if ( ext == null ) {
983986 ext = "js" ;
984987 } else if ( ext === "dts" ) {
985988 ext = "d.ts" ;
986989 }
987- filename = `${ DEFAULT_FILENAME_BASE } .${ ext } ` ;
990+ const cwd = dirname ( import . meta. dirname ) ; // Root of `oxlint` package once bundled into `dist`
991+ path = pathJoin ( cwd , `${ DEFAULT_FILENAME_BASE } .${ ext } ` ) ;
992+ } else if ( isAbsolutePath ( filename ) ) {
993+ path = filename ;
994+ } else {
995+ const cwd = dirname ( import . meta. dirname ) ; // Root of `oxlint` package once bundled into `dist`
996+ path = pathJoin ( cwd , filename ) ;
988997 }
989998
990999 try {
@@ -995,7 +1004,7 @@ function lint(test: TestCase, plugin: Plugin): Diagnostic[] {
9951004 const optionsId = setupOptions ( test ) ;
9961005
9971006 // Parse file into buffer
998- parse ( filename , test . code , parseOptions ) ;
1007+ parse ( path , test . code , parseOptions ) ;
9991008
10001009 // In conformance tests, set `context.languageOptions.ecmaVersion`.
10011010 // This is not supported outside of conformance tests.
@@ -1007,7 +1016,7 @@ function lint(test: TestCase, plugin: Plugin): Diagnostic[] {
10071016
10081017 // Lint file.
10091018 // Buffer is stored already, at index 0. No need to pass it.
1010- lintFileImpl ( filename , 0 , null , [ 0 ] , [ optionsId ] , settingsJSON , globalsJSON ) ;
1019+ lintFileImpl ( path , 0 , null , [ 0 ] , [ optionsId ] , settingsJSON , globalsJSON ) ;
10111020
10121021 // Return diagnostics
10131022 const ruleId = `${ plugin . meta ! . name ! } /${ Object . keys ( plugin . rules ) [ 0 ] } ` ;
0 commit comments