summaryrefslogtreecommitdiffstats
path: root/devtools/client/webide/test/test_build.html
blob: ffb01998c6d0689392ae9f1297685853fe025613 (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
<!DOCTYPE html>

<html>

  <head>
    <meta charset="utf8">
    <title></title>

    <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
    <script type="application/javascript;version=1.8" src="head.js"></script>
    <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  </head>

  <body>

    <script type="application/javascript;version=1.8">
      window.onload = function() {
        SimpleTest.waitForExplicitFinish();

        let {TextDecoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
        let {ProjectBuilding} = require("devtools/client/webide/modules/build");

        Task.spawn(function* () {
            let win = yield openWebIDE();
            let winProject = getProjectWindow(win);
            let AppManager = win.AppManager;

            function isProjectMarkedAsValid() {
              let details = win.frames[0];
              return !details.document.body.classList.contains("error");
            }

            // # Test first package.json like this: `{webide: {prepackage: "command line string"}}`
            let platform = Services.appShell.hiddenDOMWindow.navigator.platform;
            let testSuffix = "";
            if (platform.indexOf("Win") != -1) {
              testSuffix = "_windows";
            }

            let packagedAppLocation = getTestFilePath("build_app" + testSuffix + "1");

            let onValidated = waitForUpdate(win, "project-validated");
            let onDetails = waitForUpdate(win, "details");
            yield winProject.projectList.importPackagedApp(packagedAppLocation);
            yield onValidated;
            yield onDetails;

            let project = win.AppManager.selectedProject;

            ok(!project.manifest, "manifest includes name");
            is(project.name, "--", "Display name uses manifest name");

            let loggedMessages = [];
            let logger = function (msg) {
              loggedMessages.push(msg);
            }

            yield ProjectBuilding.build({
              project,
              logger
            });
            let packageDir = yield ProjectBuilding.getPackageDir(project);
            is(packageDir, packagedAppLocation, "no custom packagedir");
            is(loggedMessages[0], "start", "log messages are correct");
            ok(loggedMessages[1].indexOf("Running pre-package hook") != -1, "log messages are correct");
            is(loggedMessages[2], "Terminated with error code: 0", "log messages are correct");
            is(loggedMessages[3], "succeed", "log messages are correct");

            // Trigger validation
            yield AppManager.validateAndUpdateProject(AppManager.selectedProject);
            yield nextTick();

            ok("name" in project.manifest, "manifest includes name");
            is(project.name, "hello", "Display name uses manifest name");
            is(project.manifest.name, project.name, "Display name uses manifest name");

            yield OS.File.remove(OS.Path.join(packagedAppLocation, "manifest.webapp"));

            // # Now test a full featured package.json
            packagedAppLocation = getTestFilePath("build_app" + testSuffix + "2");

            onValidated = waitForUpdate(win, "project-validated");
            onDetails = waitForUpdate(win, "details");
            yield winProject.projectList.importPackagedApp(packagedAppLocation);
            yield onValidated;
            yield onDetails;

            project = win.AppManager.selectedProject;

            loggedMessages = [];
            yield ProjectBuilding.build({
              project,
              logger
            });
            packageDir = yield ProjectBuilding.getPackageDir(project);
            is(OS.Path.normalize(packageDir),
               OS.Path.join(packagedAppLocation, "stage"), "custom packagedir");
            is(loggedMessages[0], "start", "log messages are correct");
            ok(loggedMessages[1].indexOf("Running pre-package hook") != -1, "log messages are correct");
            is(loggedMessages[2], "Terminated with error code: 0", "log messages are correct");
            is(loggedMessages[3], "succeed", "log messages are correct");

            // Switch to the package dir in order to verify the generated webapp.manifest
            onValidated = waitForUpdate(win, "project-validated");
            onDetails = waitForUpdate(win, "details");
            yield winProject.projectList.importPackagedApp(packageDir);
            yield onValidated;
            yield onDetails;

            project = win.AppManager.selectedProject;

            ok("name" in project.manifest, "manifest includes name");
            is(project.name, "world", "Display name uses manifest name");
            is(project.manifest.name, project.name, "Display name uses manifest name");

            yield closeWebIDE(win);

            yield removeAllProjects();

            SimpleTest.finish();
        });
      }


    </script>
  </body>
</html>