summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/integration-tests/1-reload-same-original.js
blob: 57e65b9ea606aeed9d54f873436ccf9839a045b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

/* import-globals-from ../head.js */

/**
 * This first test will focus on original.js file whose content changes
 * which affects the related generated file: bundle.js
 *
 * In the first reload, v2/original.js will only change with new lines being added
 * before the line where we set a breakpoint. So that the breakpoint, if not
 * automatically shifted, will now be against an empty line.
 *
 * In the second reload, v3/original.js will be trimmed, so that the line
 * where we set a breakpoint against, has been removed.
 */

"use strict";

addIntegrationTask(async function testReloadingStableOriginalSource(
  testServer,
  testUrl,
  { isCompressed }
) {
  info("  # Test reload a stable source whose content changes");
  const dbg = await initDebuggerWithAbsoluteURL(testUrl, "original.js");

  info("Add initial breakpoint");
  await selectSource(dbg, "original.js");
  await addBreakpoint(dbg, "original.js", 8);

  info("Check that only one breakpoint is set");
  is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint exists");
  is(
    dbg.client.getServerBreakpointsList().length,
    1,
    "One breakpoint exists on the server"
  );

  info("Check that the breakpoint location info is correct");
  let breakpoint = dbg.selectors.getBreakpointsList(dbg)[0];
  is(breakpoint.location.line, 8);
  if (isCompressed) {
    is(breakpoint.generatedLocation.line, 1);
    is(breakpoint.generatedLocation.column, 1056);
  } else {
    is(breakpoint.generatedLocation.line, 84);
  }

  const expectedOriginalFileContentOnBreakpointLine =
    "await nonSourceMappedFunction();";
  const expectedGeneratedFileContentOnBreakpointLine =
    "await nonSourceMappedFunction();";

  info("Check that the breakpoint is displayed on the correct line in the ui");
  await assertBreakpoint(dbg, 8);

  info("Check that breakpoint is on the first line within the function `foo`");
  assertTextContentOnLine(dbg, 8, expectedOriginalFileContentOnBreakpointLine);

  info(
    "Check that the source text snippet displayed in breakpoints panel is correct"
  );
  assertBreakpointSnippet(
    dbg,
    1,
    isCompressed
      ? "nonSourceMappedFunction();"
      : "await nonSourceMappedFunction();"
  );

  info(
    "Check that the breakpoint is displayed in correct location in bundle.js (generated source)"
  );
  await selectSource(dbg, "bundle.js");
  if (isCompressed) {
    await assertBreakpoint(dbg, 1);
  } else {
    await assertBreakpoint(dbg, 84);
    assertTextContentOnLine(
      dbg,
      84,
      expectedGeneratedFileContentOnBreakpointLine
    );
  }
  info(
    "The breakpoint snippet doesn't change when moving to generated content"
  );
  assertBreakpointSnippet(
    dbg,
    1,
    isCompressed
      ? `nonSourceMappedFunction(),console.log("YO")}}]);`
      : "await nonSourceMappedFunction();"
  );

  await closeTab(dbg, "bundle.js");

  // This reload changes the content of the original file
  // which will cause the location of the breakpoint to change
  info("Reload with a new version of the file");
  testServer.switchToNextVersion();
  await reload(dbg, "bundle.js", "original.js");
  await wait(1000);

  info(
    "Check that no breakpoint is restore as original line 6 is no longer breakable"
  );
  is(dbg.selectors.getBreakpointCount(), 0, "No breakpoint exists");

  info("Invoke `foo` to trigger breakpoint");
  invokeInTab("foo");
  await wait(1000);

  // TODO: Intermittently pauses (especially when in compressed)
  // Need to investigate
  if (isPaused(dbg)) {
    await resume(dbg);
  }
  assertNotPaused(dbg);

  await closeTab(dbg, "bundle.js");

  info("Add a second breakpoint");
  await addBreakpoint(dbg, "original.js", 13);

  is(dbg.selectors.getBreakpointCount(dbg), 1, "The breakpoint exist");

  info("Check that the original location of the new breakpoint is correct");
  breakpoint = dbg.selectors.getBreakpointsList(dbg)[0];
  is(breakpoint.location.line, 13);
  if (isCompressed) {
    is(breakpoint.generatedLocation.line, 1);
    is(breakpoint.generatedLocation.column, 1089);
  } else {
    is(breakpoint.generatedLocation.line, 89);
  }
  assertBreakpointSnippet(
    dbg,
    1,
    isCompressed ? `log("HEY")` : `console.log("HEY")`
  );

  // This reload removes the content related to the lines in the original
  // file where the breakpoints where set.
  // NOTE: When we reload, the `foo` function no longer exists
  // and the original.js file is now 3 lines long
  info("Reload and observe no breakpoints");
  testServer.switchToNextVersion();
  await reload(dbg, "original.js");

  // There will initially be zero breakpoints, but wait to make sure none are
  // installed while syncing.
  await wait(1000);

  assertNotPaused(dbg);

  is(dbg.selectors.getBreakpointCount(dbg), 0, "No breakpoints");
  // TODO: fails intermitently, look to fix
  /*is(
    dbg.client.getServerBreakpointsList().length,
    2,
    "No breakpoint exists on the server"
  );*/
});