|
15 | 15 | package nodejs |
16 | 16 |
|
17 | 17 | import ( |
18 | | - "context" |
19 | 18 | "encoding/json" |
20 | 19 | "errors" |
21 | 20 | "fmt" |
@@ -535,45 +534,6 @@ func TestRunPostProcessor_CustomScripts(t *testing.T) { |
535 | 534 | } |
536 | 535 | } |
537 | 536 |
|
538 | | -func TestFormat(t *testing.T) { |
539 | | - testhelper.RequireCommand(t, "eslint") |
540 | | - outDir := t.TempDir() |
541 | | - srcDir := filepath.Join(outDir, "src") |
542 | | - if err := os.MkdirAll(srcDir, 0755); err != nil { |
543 | | - t.Fatal(err) |
544 | | - } |
545 | | - eslintConfig := `{ |
546 | | - "rules": { |
547 | | - "semi": ["error", "always"] |
548 | | - }, |
549 | | - "parserOptions": { |
550 | | - "ecmaVersion": 2020, |
551 | | - "sourceType": "module" |
552 | | - } |
553 | | - }` |
554 | | - if err := os.WriteFile(filepath.Join(outDir, ".eslintrc.json"), []byte(eslintConfig), 0644); err != nil { |
555 | | - t.Fatal(err) |
556 | | - } |
557 | | - testFile := filepath.Join(srcDir, "index.ts") |
558 | | - if err := os.WriteFile(testFile, []byte("export const foo = 'bar'"), 0644); err != nil { |
559 | | - t.Fatal(err) |
560 | | - } |
561 | | - library := &config.Library{ |
562 | | - Name: "google-cloud-test", |
563 | | - Output: outDir, |
564 | | - } |
565 | | - if err := Format(t.Context(), library); err != nil { |
566 | | - t.Fatal(err) |
567 | | - } |
568 | | - got, err := os.ReadFile(testFile) |
569 | | - if err != nil { |
570 | | - t.Fatal(err) |
571 | | - } |
572 | | - if !strings.Contains(string(got), "bar';") { |
573 | | - t.Errorf("expected fixed content with semicolon, got: %q", string(got)) |
574 | | - } |
575 | | -} |
576 | | - |
577 | 537 | func TestRunPostProcessor_PreservesFiles(t *testing.T) { |
578 | 538 | testhelper.RequireCommand(t, "gapic-node-processing") |
579 | 539 | testhelper.RequireCommand(t, "compileProtos") |
@@ -892,61 +852,6 @@ func TestCopySamplesFromStaging_NonExistentDir(t *testing.T) { |
892 | 852 | } |
893 | 853 | } |
894 | 854 |
|
895 | | -func TestFormat_CanceledContext(t *testing.T) { |
896 | | - ctx, cancel := context.WithCancel(t.Context()) |
897 | | - cancel() |
898 | | - |
899 | | - library := &config.Library{ |
900 | | - Name: "google-cloud-test", |
901 | | - Output: t.TempDir(), |
902 | | - } |
903 | | - err := Format(ctx, library) |
904 | | - if err == nil { |
905 | | - t.Fatal("expected error from canceled context, got nil") |
906 | | - } |
907 | | - if !errors.Is(err, context.Canceled) { |
908 | | - t.Errorf("expected context.Canceled, got: %v", err) |
909 | | - } |
910 | | -} |
911 | | - |
912 | | -func TestFormat_ExitCode1(t *testing.T) { |
913 | | - testhelper.RequireCommand(t, "eslint") |
914 | | - |
915 | | - outDir := t.TempDir() |
916 | | - srcDir := filepath.Join(outDir, "src") |
917 | | - if err := os.MkdirAll(srcDir, 0755); err != nil { |
918 | | - t.Fatal(err) |
919 | | - } |
920 | | - |
921 | | - // Configure eslint with an "error" rule that cannot be auto-fixed. |
922 | | - // eslint exits 1 when unfixable errors remain after --fix. |
923 | | - eslintConfig := `{ |
924 | | - "rules": { |
925 | | - "no-eval": "error" |
926 | | - }, |
927 | | - "parserOptions": { |
928 | | - "ecmaVersion": 2020, |
929 | | - "sourceType": "module" |
930 | | - } |
931 | | - }` |
932 | | - if err := os.WriteFile(filepath.Join(outDir, ".eslintrc.json"), []byte(eslintConfig), 0644); err != nil { |
933 | | - t.Fatal(err) |
934 | | - } |
935 | | - // eval() triggers no-eval warning which --fix cannot remove. |
936 | | - if err := os.WriteFile(filepath.Join(srcDir, "index.js"), []byte("eval('1+1');\n"), 0644); err != nil { |
937 | | - t.Fatal(err) |
938 | | - } |
939 | | - |
940 | | - library := &config.Library{ |
941 | | - Name: "google-cloud-test", |
942 | | - Output: outDir, |
943 | | - } |
944 | | - // Format should tolerate exit code 1 (lint warnings). |
945 | | - if err := Format(t.Context(), library); err != nil { |
946 | | - t.Fatal(err) |
947 | | - } |
948 | | -} |
949 | | - |
950 | 855 | func TestGenerateAPI_NoProtos(t *testing.T) { |
951 | 856 | googleapisDir := t.TempDir() |
952 | 857 | repoRoot := t.TempDir() |
|
0 commit comments