-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
9 changed files
with
153 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
}, | ||
"keywords": [ | ||
"textlint", | ||
"textlintplugin", | ||
"latex" | ||
], | ||
"author": "TANIGUCHI Masaya", | ||
|
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,100 @@ | ||
import child_process from "child_process"; | ||
import fs from "fs"; | ||
import os from "os"; | ||
import path from "path"; | ||
import { suite, expect, test } from "vitest"; | ||
|
||
// These tests requires "E2E=true" environment variable to run and `npm` command should be callable globally. | ||
suite.concurrent("e2e", () => { | ||
["commonjs", "module"].forEach((moduleType) => { | ||
runE2ETestFor(moduleType, async ({ workDir }) => { | ||
const execCommand = ( | ||
command: string, | ||
args: string[], | ||
): child_process.SpawnSyncReturns<Buffer> => { | ||
return child_process.spawnSync(command, args, { | ||
cwd: workDir, | ||
stdio: "ignore", | ||
}); | ||
}; | ||
const npmInstall = execCommand("npm", ["install"]); | ||
expect(npmInstall.status).toBe(0); | ||
const textlintNoErr = execCommand("npx", ["textlint", "no-error.tex"]); | ||
expect(textlintNoErr.status).toBe(0); | ||
const textlintErr = execCommand("npx", ["textlint", "error.tex"]); | ||
expect(textlintErr.status).toBe(1); | ||
const textlintNoErrByComment = execCommand("npx", [ | ||
"textlint", | ||
"no-error-by-comment.tex", | ||
]); | ||
expect(textlintNoErrByComment.status).toBe(0); | ||
}); | ||
}); | ||
}); | ||
|
||
interface E2EContext { | ||
workDir: string; | ||
} | ||
|
||
// runE2ETestFor is a test runner for end-to-end tests. | ||
// This will prepare test environment and clean up after the test. | ||
// This will also skip the test if "E2E" environment variable is not set to "true". | ||
const runE2ETestFor = test.extend<E2EContext>({ | ||
workDir: async ({ task, skip }, use) => { | ||
const e2e = process.env.E2E; | ||
if (!e2e && e2e !== "true") { | ||
skip(); | ||
} | ||
// Task name should be a module type. | ||
const workDir = prepare(task.name); | ||
try { | ||
await use(workDir); | ||
} finally { | ||
if (fs.existsSync(workDir)) { | ||
fs.rmSync(workDir, { recursive: true }); | ||
} | ||
} | ||
}, | ||
}); | ||
|
||
// prepare will create temporary directory and write files for testing. | ||
// This returns the path of the temporary directory. | ||
// moduleType should be "commonjs" or "module". It will be used for package.json. | ||
// Deleting the temporary directory is the responsibility of the caller. | ||
const prepare = (moduleType: string): string => { | ||
const templateDir = path.join(__dirname, "templates"); | ||
|
||
const packageRoot = path.dirname(__dirname); | ||
const rootPackageJson = fs.readFileSync( | ||
path.join(packageRoot, "package.json"), | ||
"utf-8", | ||
); | ||
const textlintVersion = | ||
JSON.parse(rootPackageJson)["devDependencies"]["@textlint/kernel"]; | ||
|
||
const readFromTmplDir = (filename: string) => | ||
fs.readFileSync(path.join(templateDir, filename), "utf-8"); | ||
|
||
const packageJsonTmpl = readFromTmplDir("package.json.tmpl"); | ||
const packageJson = packageJsonTmpl | ||
.replace(/%PACKAGE_TYPE%/g, moduleType) | ||
.replace(/%TEXTLINT_VERSION%/g, textlintVersion) | ||
.replace(/%TEXTLINT_PLUGIN_LATEX2E_LOCATION%/g, `file://${packageRoot}`); | ||
const textlintrcTmpl = readFromTmplDir(".textlintrc.tmpl"); | ||
const noErrorTexFile = readFromTmplDir("no-error.tex.tmpl"); | ||
const noErrorByCommentTexFile = readFromTmplDir( | ||
"no-error-by-comment.tex.tmpl", | ||
); | ||
const errorTexFile = readFromTmplDir("error.tex.tmpl"); | ||
|
||
const tmpDir = fs.mkdtempSync(os.tmpdir()); | ||
Check failure on line 90 in test/e2e.test.ts GitHub Actions / build (18.x)test/e2e.test.ts > e2e > commonjs
Check failure on line 90 in test/e2e.test.ts GitHub Actions / build (18.x)test/e2e.test.ts > e2e > module
Check failure on line 90 in test/e2e.test.ts GitHub Actions / build (20.x)test/e2e.test.ts > e2e > commonjs
Check failure on line 90 in test/e2e.test.ts GitHub Actions / build (20.x)test/e2e.test.ts > e2e > module
|
||
const writeToTmpDir = (filename: string, content: string): void => { | ||
fs.writeFileSync(path.join(tmpDir, filename), content); | ||
}; | ||
writeToTmpDir(".textlintrc", textlintrcTmpl); | ||
writeToTmpDir("no-error.tex", noErrorTexFile); | ||
writeToTmpDir("error.tex", errorTexFile); | ||
writeToTmpDir("no-error-by-comment.tex", noErrorByCommentTexFile); | ||
writeToTmpDir("package.json", packageJson); | ||
return tmpDir; | ||
}; |
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,9 @@ | ||
{ | ||
"plugins": ["@textlint/textlint-plugin-latex2e"], | ||
"filters": { | ||
"comments": true | ||
}, | ||
"rules": { | ||
"no-todo": true | ||
} | ||
} |
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,9 @@ | ||
\documentclass{article} | ||
|
||
\begin{document} | ||
|
||
\section{intro} | ||
|
||
TODO: write something | ||
|
||
\end{document} |
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,11 @@ | ||
\documentclass{article} | ||
|
||
\begin{document} | ||
|
||
\section{intro} | ||
|
||
% textlint-disable no-todo | ||
TODO: write something | ||
% textlint-enable no-todo | ||
|
||
\end{document} |
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,9 @@ | ||
\documentclass{article} | ||
|
||
\begin{document} | ||
|
||
\section{intro} | ||
|
||
This is a sample tex file. | ||
|
||
\end{document} |
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,11 @@ | ||
{ | ||
"name": "textlint-plugin-latex2e-integration-test", | ||
"version": "1.0.0", | ||
"type": "%PACKAGE_TYPE%", | ||
"dependencies": { | ||
"textlint": "%TEXTLINT_VERSION%", | ||
"@textlint/textlint-plugin-latex2e": "%TEXTLINT_PLUGIN_LATEX2E_LOCATION%", | ||
"textlint-rule-no-todo": "2.0.1", | ||
"textlint-filter-rule-comments": "1.2.2" | ||
} | ||
} |