Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,114 +42,114 @@

class TestESLint {

private static IProject project;

@BeforeAll
public static void setUpProject() throws Exception {
AllCleanRule.closeIntro();
AllCleanRule.enableLogging();

String projectName = TestESLint.class.getName() + System.nanoTime();
IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(projectName);
desc.setLocation(projectLocation);
File projectDirectory = projectLocation.toFile();
projectDirectory.mkdir();
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/.eslintrc")) {
Files.copy(eslintRc, new File(projectDirectory, ".eslintrc").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/tsconfig.json")) {
Files.copy(eslintRc, new File(projectDirectory, "tsconfig.json").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/package.json")) {
Files.copy(eslintRc, new File(projectDirectory, "package.json").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) {
Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.js").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) {
Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.jsx").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) {
Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.ts").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) {
Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.tsx").toPath());
}
ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts")
.directory(projectDirectory);
Process dependencyInstaller = builder.start();
System.out.println(builder.command().toString());
String result = dependencyInstaller.errorReader().lines().collect(Collectors.joining("\n"));
System.out.println("Error Stream: >>>\n" + result + "\n<<<");

result = dependencyInstaller.inputReader().lines().collect(Collectors.joining("\n"));
System.out.println("Output Stream: >>>\n" + result + "\n<<<");

assertEquals(0, dependencyInstaller.waitFor(), "npm install didn't complete properly");
project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
project.create(desc, null);
project.open(null);
}

@BeforeEach
public void setUpTestCase() {
AllCleanRule.enableLogging();
}

@AfterAll
public static void cleanUp() throws Exception {
new AllCleanRule().afterEach(null);
}

@Test
void testESLintDiagnosticsInJS() throws Exception {
IFile file = project.getFile("ESLintProj.js");
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertESLintIndentMarkerExists(file);
}

@Test
void testESLintDiagnosticsInTS() throws Exception {
IFile file = project.getFile("ESLintProj.ts");
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertESLintIndentMarkerExists(file);
}

@Test
void testESLintDiagnosticsInJSX() throws Exception {
IFile file = project.getFile("ESLintProj.jsx");
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertESLintIndentMarkerExists(file);
}

@Test
void testESLintDiagnosticsInTSX() throws Exception {
IFile file = project.getFile("ESLintProj.tsx");
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertESLintIndentMarkerExists(file);
}

private void assertESLintIndentMarkerExists(IFile file) throws PartInitException {
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 10000, () -> {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}), "Diagnostic not published");

assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> {
try {
return Arrays.asList(file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO))
.stream().filter(Objects::nonNull)
.anyMatch(m -> m.getAttribute(IMarker.MESSAGE, null).toLowerCase().contains("indentation"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}), "Diagnostic content is incorrect");
}
private static IProject project;

@BeforeAll
public static void setUpProject() throws Exception {
AllCleanRule.closeIntro();
AllCleanRule.enableLogging();

String projectName = TestESLint.class.getName() + System.nanoTime();
IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(projectName);
desc.setLocation(projectLocation);
File projectDirectory = projectLocation.toFile();
projectDirectory.mkdir();
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/eslint.config.mjs")) {
Files.copy(eslintRc, new File(projectDirectory, "eslint.config.mjs").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/tsconfig.json")) {
Files.copy(eslintRc, new File(projectDirectory, "tsconfig.json").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/package.json")) {
Files.copy(eslintRc, new File(projectDirectory, "package.json").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) {
Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.js").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) {
Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.jsx").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) {
Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.ts").toPath());
}
try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) {
Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.tsx").toPath());
}
ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts")
.directory(projectDirectory);
Process dependencyInstaller = builder.start();
System.out.println(builder.command().toString());
String result = dependencyInstaller.errorReader().lines().collect(Collectors.joining("\n"));
System.out.println("Error Stream: >>>\n" + result + "\n<<<");

result = dependencyInstaller.inputReader().lines().collect(Collectors.joining("\n"));
System.out.println("Output Stream: >>>\n" + result + "\n<<<");

assertEquals(0, dependencyInstaller.waitFor(), "npm install didn't complete properly");
project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
project.create(desc, null);
project.open(null);
}

@BeforeEach
public void setUpTestCase() {
AllCleanRule.enableLogging();
}

@AfterAll
public static void cleanUp() throws Exception {
new AllCleanRule().afterEach(null);
}

@Test
void testESLintDiagnosticsInJS() throws Exception {
IFile file = project.getFile("ESLintProj.js");
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertESLintIndentMarkerExists(file);
}

@Test
void testESLintDiagnosticsInTS() throws Exception {
IFile file = project.getFile("ESLintProj.ts");
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertESLintIndentMarkerExists(file);
}

@Test
void testESLintDiagnosticsInJSX() throws Exception {
IFile file = project.getFile("ESLintProj.jsx");
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertESLintIndentMarkerExists(file);
}

@Test
void testESLintDiagnosticsInTSX() throws Exception {
IFile file = project.getFile("ESLintProj.tsx");
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertESLintIndentMarkerExists(file);
}

private void assertESLintIndentMarkerExists(IFile file) throws PartInitException {
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 10000, () -> {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}), "Diagnostic not published");

assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> {
try {
return Arrays.asList(file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO))
.stream().filter(Objects::nonNull)
.anyMatch(m -> m.getAttribute(IMarker.MESSAGE, null).toLowerCase().contains("indentation"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}), "Diagnostic content is incorrect");
}
}
12 changes: 0 additions & 12 deletions org.eclipse.wildwebdeveloper.tests/testProjects/eslint/.eslintrc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import tsParser from '@typescript-eslint/parser';

export default [
{
rules: {
indent: 'error',
},
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
languageOptions: {
parser: tsParser,
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^8.56.0",
"@typescript-eslint/parser": "^8.56.0",
"eslint": "^8.57.1",
"eslint": "^10.1.0",
"typescript": "5.9.3"
},
"packageManager": "npm@11"
Expand Down
Loading