timezones-ical-library 1.11.1 → 2.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.
package/test/tests.js CHANGED
@@ -1,23 +1,64 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
2
- // eslint-disable-next-line security/detect-child-process
3
- const execSync = require('child_process').execSync;
1
+ const { execSync, spawnSync } = require('child_process');
2
+
3
+ const testCases = [
4
+ 'CST6CDT',
5
+ 'GMT0',
6
+ 'Europe/Berlin',
7
+ 'America/New_York',
8
+ 'America/Argentina/Buenos_Aires',
9
+ 'Antarctica/Casey',
10
+ 'Africa/Bangui',
11
+ ];
4
12
 
5
13
  try {
6
- execSync('npm run build', { stdio: [0, 1, 2] });
14
+ execSync('npm run build:lib-only', { stdio: [0, 1, 2] });
15
+
16
+ const testCasesString = JSON.stringify(testCases);
17
+
18
+ console.log('\nšŸŽļø Running Tests...');
19
+
20
+ // Test ES Module import
21
+ try {
22
+ const result = spawnSync('node', ['test/load-module.mjs', testCasesString], { encoding: 'utf8' });
23
+ if (result.stdout) process.stdout.write(result.stdout);
24
+ if (result.status !== 0 || (result.stderr && result.stderr.length > 0)) {
25
+ throw new Error('Test script passed with errors');
26
+ }
27
+ console.log('āœ… Importing the script as module and running tests\n');
28
+ } catch (error) {
29
+ console.error('āŒ Something went wrong with testing the ES Module setup\n');
30
+ throw error;
31
+ }
7
32
 
33
+ // Test CommonJS require
8
34
  try {
9
- execSync('node test/load-module.mjs', { stdio: [0, 1, 2] });
10
- console.log('TEST SUCCESSFUL: importing the script as module\n');
35
+ const result = spawnSync('node', ['test/load-commonjs.cjs', testCasesString], { encoding: 'utf8' });
36
+ if (result.stdout) process.stdout.write(result.stdout);
37
+ if (result.status !== 0 || (result.stderr && result.stderr.length > 0)) {
38
+ throw new Error('Test script passed with errors');
39
+ }
40
+ console.log('āœ… CommonJS init via require and running tests\n');
11
41
  } catch (error) {
12
- console.log('FAILED: Something went wrong with testing the ES Module setup\n');
42
+ console.error('āŒ Something went wrong with testing the CommonJS setup\n');
13
43
  throw error;
14
44
  }
15
45
 
46
+ // Test whether there is an ics file per test case in the api folder
47
+ console.log('\nāš™ļø Testing for ics files in the API folder:\n');
16
48
  try {
17
- execSync('node test/load-commonjs.cjs', { stdio: [0, 1, 2] });
18
- console.log('TEST SUCCESSFUL: commonJS init via require\n');
49
+ testCases.forEach((tz) => {
50
+ const fs = require('fs');
51
+ const path = `api/${tz}.ics`;
52
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
53
+ if (!fs.existsSync(path)) {
54
+ throw new Error(`šŸ”“ Missing file for time zone ${tz} at API folder`);
55
+ }
56
+ console.log(`🟢 Found ics file for time zone ${tz} at API folder`);
57
+ });
58
+ console.log('āœ… All time zones have a corresponding ics file in the API folder\n');
19
59
  } catch (error) {
20
- console.log('FAILED: Something went wrong with testing the commonJS setup\n');
60
+ console.error(error.message);
61
+ console.error('āŒ Could not find all ics files in the API folder\n');
21
62
  throw error;
22
63
  }
23
64
 
@@ -27,10 +68,10 @@ try {
27
68
  if (error) {
28
69
  throw error;
29
70
  }
30
- console.log(`${dirToDrop} deleted again`);
31
- console.log('All Tests SUCCESSFUL!\n');
71
+ console.log(`... ${dirToDrop} directory deleted again`);
72
+ console.log('\nšŸŽ‰ All Tests SUCCESSFUL!\n');
32
73
  });
74
+ // eslint-disable-next-line no-unused-vars
33
75
  } catch (error) {
34
- console.log('FAILED: Something went wrong with the npm build script while testing\n');
35
- throw error;
76
+ console.error('\n😭 FAILED: Tests did not pass unfortunately.\n');
36
77
  }
@@ -1 +0,0 @@
1
- { "extends": "../../.eslintrc.json", "env": { "node": true }, "plugins": ["commonjs"] }
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "../.eslintrc.json",
3
- "env": {
4
- "node": true
5
- },
6
- "plugins": ["commonjs"]
7
- }