(code string)
| 463 | result := &CodeExecResult{Language: "javascript"} |
| 464 | start := time.Now() |
| 465 | |
| 466 | if _, err := exec.LookPath("node"); err != nil { |
| 467 | return nil |
| 468 | } |
| 469 | |
| 470 | dir, err := os.MkdirTemp("", "ark-verify-*") |
| 471 | if err != nil { |
| 472 | return nil |
| 473 | } |
| 474 | defer os.RemoveAll(dir) |
| 475 | |
| 476 | filePath := filepath.Join(dir, "verify.js") |
| 477 | if err := os.WriteFile(filePath, []byte(code), 0644); err != nil { |
| 478 | return nil |
| 479 | } |
| 480 | |
| 481 | // Syntax check |
| 482 | syntaxCmd := exec.Command("node", "--check", filePath) |
| 483 | syntaxOutput, syntaxErr := syntaxCmd.CombinedOutput() |
| 484 | result.Duration = time.Since(start) |
| 485 | |
| 486 | if syntaxErr != nil { |
| 487 | result.Compiled = false |
| 488 | result.Error = cleanCompilerError(string(syntaxOutput)) |
| 489 | return result |
| 490 | } |
| 491 | result.Compiled = true |
| 492 | |
| 493 | // Run |
| 494 | result.Ran = runWithTimeout(dir, "node", []string{filePath}, result, 10*time.Second) |
| 495 | result.Linted = true |
| 496 | |
| 497 | return result |
| 498 | } |
| 499 | |
| 500 | type testResult struct { |
| 501 | passed bool |
| 502 | output string |
| 503 | } |
| 504 |
no test coverage detected