generator-discord 1.3.3 → 1.3.4

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.
@@ -6,5 +6,5 @@ edition = "2021"
6
6
  # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
7
 
8
8
  [dependencies]
9
- serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
9
+ serenity = { version = "0.11.7", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
10
10
  tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
@@ -6,7 +6,7 @@ import path from 'path';
6
6
  import url from 'url';
7
7
 
8
8
  const __dirname = url.fileURLToPath(new URL('../', import.meta.url));
9
- const TIMEOUT = 30_000; // 30 seconds
9
+ const DEFAULT_TIMEOUT = 60_000; // 1 minute
10
10
 
11
11
  dotenv.config();
12
12
 
@@ -38,14 +38,13 @@ describe('Check if the templates work', () => {
38
38
  })
39
39
  .withAnswers(defaultAnswers)
40
40
  .then(async () => {
41
- const result = await runBot('node', ['./dist/src/index.js'], resultRoot);
41
+ const result = await runBot('node', ['./dist/src/index.js'], resultRoot, DEFAULT_TIMEOUT);
42
42
  expect(result).toContain(BOT_OUTPUT_START);
43
43
  });
44
44
 
45
45
  context.cleanup();
46
46
  }, 120_000);
47
47
 
48
-
49
48
  test.skip('Should generate and run Python Discord Bot', async () => {
50
49
  const context = createHelpers({}).run(moduleRoot);
51
50
 
@@ -55,44 +54,87 @@ describe('Check if the templates work', () => {
55
54
  .onGenerator(generator => {
56
55
  generator.destinationRoot(targetRoot);
57
56
  })
58
- .withAnswers({...defaultAnswers, botType: 'python' })
57
+ .withAnswers({ ...defaultAnswers, botType: 'python' })
59
58
  .then(async () => {
60
59
  // install dependencies
61
60
  await exec('pip3 install -r requirements.txt', { cwd: resultRoot });
62
61
 
63
- const result = await runBot('python', ['main.py'], resultRoot);
62
+ const result = await runBot('python', ['./main.py'], resultRoot, DEFAULT_TIMEOUT);
64
63
  expect(result).toContain(BOT_OUTPUT_START);
65
64
  });
66
65
 
67
66
  context.cleanup();
68
67
  }, 120_000);
69
- });
70
68
 
69
+ test('Should generate and run JavaScript Discord Bot', async () => {
70
+ const context = createHelpers({}).run(moduleRoot);
71
+
72
+ context.targetDirectory = targetRoot;
73
+ context.cleanTestDirectory(true);
74
+ await context
75
+ .onGenerator(generator => {
76
+ generator.destinationRoot(targetRoot);
77
+ })
78
+ .withAnswers({ ...defaultAnswers, botType: 'javascript' })
79
+ .then(async () => {
80
+ const result = await runBot('node', ['./src/index.js'], resultRoot, DEFAULT_TIMEOUT);
81
+ expect(result).toContain(BOT_OUTPUT_START);
82
+ });
83
+
84
+ context.cleanup();
85
+ }, 120_000);
71
86
 
72
- async function runBot(command: string, args: string[], root: string): Promise<string> {
73
- const childProcess = spawn(command, args, { cwd: root, stdio: 'pipe', timeout: TIMEOUT });
87
+ test('Should generate and run Rust Discord Bot', async () => {
88
+ const context = createHelpers({}).run(moduleRoot);
89
+
90
+ context.targetDirectory = targetRoot;
91
+ context.cleanTestDirectory(true);
92
+ await context
93
+ .onGenerator(generator => {
94
+ generator.destinationRoot(targetRoot);
95
+ })
96
+ .withAnswers({ ...defaultAnswers, botType: 'rust' })
97
+ .withArguments(['skip-build'])
98
+ .then(async () => {
99
+ const result = await runBot('cargo', ['run', '--release', '--quiet'] , resultRoot, 120_000); // 2 minutes
100
+ expect(result).toContain(BOT_OUTPUT_START);
101
+ });
102
+
103
+ context.cleanup();
104
+ }, 180_000); // 3 minutes
105
+ });
106
+
107
+ /** Run a command in a child process and return the output
108
+ * @param {string} command The command to run
109
+ * @param {string[]} args The arguments to pass to the command
110
+ * @param {string} root The root directory to run the command in
111
+ * @param {number} timeoutTime The time in milliseconds to wait before timing out
112
+ * @returns {Promise<string>} The output of the command
113
+ */
114
+ async function runBot(command: string, args: string[], root: string, timeoutTime: number): Promise<string> {
115
+ const childProcess = spawn(command, args, { cwd: root, timeout: timeoutTime });
74
116
 
75
117
  const result = await new Promise<string>((resolve) => {
76
118
  // timeout
77
- const timeout = setTimeout(() => {
119
+ const safetyTimeout = setTimeout(() => {
78
120
  resolve('TIMEOUT');
79
- }, TIMEOUT);
121
+ }, timeoutTime);
80
122
 
81
123
  // output
82
124
  childProcess.stdout.on('data', (data) => {
83
- clearTimeout(timeout);
84
-
125
+ clearTimeout(safetyTimeout);
126
+
85
127
  resolve(data.toString());
86
128
  });
87
129
 
88
130
  childProcess.stderr.on('data', (data) => {
89
- clearTimeout(timeout);
131
+ clearTimeout(safetyTimeout);
90
132
 
91
133
  resolve(data.toString());
92
134
  });
93
135
 
94
136
  childProcess.on('close', () => {
95
- clearTimeout(timeout);
137
+ clearTimeout(safetyTimeout);
96
138
  });
97
139
 
98
140
  });
@@ -102,4 +144,4 @@ async function runBot(command: string, args: string[], root: string): Promise<st
102
144
  }
103
145
 
104
146
 
105
- const BOT_OUTPUT_START = 'Bot is logged in as';
147
+ const BOT_OUTPUT_START = 'Bot is logged in as';