forked from swc-project/swc-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { AVAILABLE_EXTENSION_PATTERN, AVAILABLE_TS_EXTENSION_PATTERN } from '@swc-node/register/register.ts' | ||
import test from 'ava' | ||
import * as ts from 'typescript' | ||
|
||
const tsExtensions = [ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Mts, ts.Extension.Cts] | ||
const nonTsExtensions = [ts.Extension.Js, ts.Extension.Jsx, ts.Extension.Mjs, ts.Extension.Cjs, '.es6', '.es'] | ||
const defaultExtensions = [...tsExtensions, ...nonTsExtensions] | ||
const ignoreExtensions = ['.txt', '.json', '.xml'] | ||
|
||
test(`AVAILABLE_TS_EXTENSION_PATTERN matches TypeScript extensions`, (t) => { | ||
tsExtensions.forEach((ext) => { | ||
t.true(AVAILABLE_TS_EXTENSION_PATTERN.test(`file${ext}`)) | ||
}) | ||
}) | ||
|
||
test(`AVAILABLE_TS_EXTENSION_PATTERN does not match d.ts`, (t) => { | ||
tsExtensions.forEach((ext) => { | ||
t.false(AVAILABLE_TS_EXTENSION_PATTERN.test(`file.d${ext}`)) | ||
}) | ||
}) | ||
|
||
test(`AVAILABLE_TS_EXTENSION_PATTERN does not match non-ts extensions`, (t) => { | ||
;[...nonTsExtensions, ...ignoreExtensions].forEach((ext) => { | ||
t.false(AVAILABLE_TS_EXTENSION_PATTERN.test(`file${ext}`)) | ||
}) | ||
}) | ||
|
||
test(`AVAILABLE_EXTENSION_PATTERN matches default extensions`, (t) => { | ||
defaultExtensions.forEach((ext) => { | ||
t.true(AVAILABLE_EXTENSION_PATTERN.test(`file${ext}`)) | ||
}) | ||
}) | ||
|
||
test(`AVAILABLE_EXTENSION_PATTERN does not match non-default extensions`, (t) => { | ||
ignoreExtensions.forEach((ext) => { | ||
t.false(AVAILABLE_EXTENSION_PATTERN.test(`file${ext}`)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.