superuser.app 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +296 -0
  3. package/commands/domains/add.js +102 -0
  4. package/commands/domains/list.js +71 -0
  5. package/commands/domains/remove.js +97 -0
  6. package/commands/domains/verify.js +130 -0
  7. package/commands/g/endpoint.js +32 -0
  8. package/commands/g/test.js +42 -0
  9. package/commands/init.js +220 -0
  10. package/commands/login.js +123 -0
  11. package/commands/me.js +54 -0
  12. package/commands/organizations/create.js +68 -0
  13. package/commands/profile.js +58 -0
  14. package/commands/register.js +127 -0
  15. package/commands/run.js +194 -0
  16. package/commands/serve.js +35 -0
  17. package/commands/test.js +68 -0
  18. package/commands/up.js +257 -0
  19. package/commands/update.js +84 -0
  20. package/commands/version.js +31 -0
  21. package/helpers/constants.js +3 -0
  22. package/helpers/draw_box.js +38 -0
  23. package/helpers/draw_table.js +144 -0
  24. package/helpers/file_writer.js +101 -0
  25. package/helpers/generate/endpoint/_index.js +44 -0
  26. package/helpers/generate/test/_index.js +112 -0
  27. package/helpers/load_package.js +62 -0
  28. package/helpers/local_server.js +72 -0
  29. package/helpers/settings_manager.js +108 -0
  30. package/helpers/verify_packages.js +85 -0
  31. package/index.js +7 -0
  32. package/package.json +31 -0
  33. package/src/endpoint/functions/index.js +35 -0
  34. package/src/init/__.env +1 -0
  35. package/src/init/__.env.production +1 -0
  36. package/src/init/__.env.staging +1 -0
  37. package/src/init/__.gitignore +6 -0
  38. package/src/init/functions/index.js +15 -0
  39. package/src/init/instant.package.json +3 -0
  40. package/src/init/package.json +16 -0
  41. package/src/init/serve.instant.js +52 -0
  42. package/src/init/test/run.js +45 -0
  43. package/src/init/test/tests/_index.js +53 -0
  44. package/src/test/blank.mjs +16 -0
  45. package/src/test/endpoint.mjs +20 -0
@@ -0,0 +1,45 @@
1
+ import InstantAPI from '@instant.dev/api';
2
+ import dotenv from 'dotenv';
3
+
4
+ const Gateway = InstantAPI.Gateway;
5
+ const TestEngine = InstantAPI.TestEngine;
6
+ const PORT = 7357; // Leetspeak for "TEST"; can be anything
7
+
8
+ // (1) Load environment variables; make sure NODE_ENV is "test"
9
+ dotenv.config({path: `.env.test`});
10
+ process.env.NODE_ENV = `test`;
11
+
12
+ // (2) Initialize and load tests; set PORT for request mocking
13
+ const testEngine = new TestEngine(PORT);
14
+ await testEngine.initialize('./test/tests');
15
+
16
+ // (3) Setup; create objects and infrastructure for tests
17
+ // Arguments returned here will be sent to .finish()
18
+ await testEngine.setup(async () => {
19
+
20
+ console.log();
21
+ console.log(`# Starting test gateway on localhost:${PORT} ... `);
22
+ console.log();
23
+
24
+ // Start Gateway; {debug: true} will print logs
25
+ const gateway = new Gateway({debug: false});
26
+ gateway.load(process.cwd()); // load routes from filesystem
27
+ gateway.listen(PORT); // start server
28
+
29
+ return { gateway };
30
+
31
+ });
32
+
33
+ // (4) Run tests; use first argument to specify a test
34
+ const args = process.argv.slice(3);
35
+ if (args[0]) {
36
+ await testEngine.run(args[0]);
37
+ } else {
38
+ await testEngine.runAll();
39
+ }
40
+
41
+ // (5) Finish; close Gateway
42
+ // Receive arguments from .setup()
43
+ testEngine.finish(async ({ gateway }) => {
44
+ gateway.close();
45
+ });
@@ -0,0 +1,53 @@
1
+ const chai = await import('chai');
2
+ const expect = chai.expect;
3
+
4
+ // Defaults to the filename if no name exported
5
+ export const name = `Main Tests`;
6
+
7
+ /**
8
+ * Main Tests
9
+ * You can pass in as many arguments as you would like in `test/run.js`
10
+ * @param {any} setupResult Result of the function passed to `.setup()` in `test/run.js`
11
+ */
12
+ export default async function (setupResult) {
13
+
14
+ before(async () => {
15
+
16
+ // Set up anything you want executed before your test in this file
17
+
18
+ });
19
+
20
+ it('Loads a startup page', async () => {
21
+
22
+ const testUsername = `test user`;
23
+
24
+ // TestEngine can make HTTP requests easily via:
25
+ // this.get(path, queryParams, headers);
26
+ // this.post(path, bodyParams, headers);
27
+ // this.put(path, bodyParams, headers);
28
+ // this.del(path, queryParams, headers);
29
+
30
+ // Note that Instant API merges queryParams and bodyParams,
31
+ // you should never need to test with both
32
+
33
+ let result = await this.get(`/`, {username: testUsername});
34
+
35
+ expect(result).to.exist;
36
+ expect(result.statusCode).to.equal(200);
37
+ expect(result.headers).to.exist;
38
+ expect(result.headers['x-instant-api']).to.equal('true');
39
+ expect(result.headers['content-type']).to.equal('application/json');
40
+ expect(result.body).to.exist;
41
+ expect(result.json).to.exist; // will exist on application/json responses
42
+ expect(result.json.message).to.exist;
43
+ expect(result.json.message).to.equal(`Welcome to Superuser, ${testUsername}!`);
44
+
45
+ });
46
+
47
+ after(async () => {
48
+
49
+ // Tear down and clean up from tests
50
+
51
+ });
52
+
53
+ };
@@ -0,0 +1,16 @@
1
+ const chai = await import('chai');
2
+ const expect = chai.expect;
3
+
4
+ /**
5
+ * Name test
6
+ * @param {any} setupResult Result of the function passed to `.setup()` in `test/run.js`
7
+ */
8
+ export default async function (setupResult) {
9
+
10
+ it('Runs a test', async () => {
11
+
12
+ expect(true).to.equal(true);
13
+
14
+ });
15
+
16
+ };
@@ -0,0 +1,20 @@
1
+ const chai = await import('chai');
2
+ const expect = chai.expect;
3
+
4
+ export const name = `Endpoint tests: Pathname`;
5
+ /**
6
+ * Endpoint tests: Pathname
7
+ * @param {any} setupResult Result of the function passed to `.setup()` in `test/run.js`
8
+ */
9
+ export default async function (setupResult) {
10
+
11
+ // Method Begin
12
+ it('Responds to HTTP Method', async () => {
13
+
14
+ let result = await this.__method__('Pathname', {});
15
+
16
+ expect(result.json).to.exist;
17
+
18
+ }); // Method End
19
+
20
+ };