Skip to content

Commit e6019be

Browse files
authored
chore(tests): Restructure unit test directories (#1587)
1 parent bf9f80d commit e6019be

File tree

211 files changed

+77
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+77
-104
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
run: |
127127
npm ci
128128
npm run lint
129-
npm run unit-tests
129+
npm run cover
130130
env:
131131
CI: true
132132

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = defineConfig([
2626
globalIgnores([
2727
'**/coverage/',
2828
'templates/project/',
29-
'tests/spec/unit/fixtures/'
29+
'tests/spec/fixtures/'
3030
]),
3131
...nodeConfig,
3232
...nodeTestConfig.map(config => ({

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
"scripts": {
1717
"prepare": "cordova-js build > templates/project/www/cordova.js",
1818
"pretest": "npm run lint",
19-
"test": "npm run coverage && npm run objc-tests",
20-
"coverage": "c8 jasmine --config=tests/spec/coverage.json",
21-
"e2e-tests": "jasmine tests/spec/create.spec.js",
22-
"objc-tests": "xcodebuild -quiet test -workspace tests/cordova-ios.xcworkspace -scheme CordovaTestApp -destination \"platform=iOS Simulator,name=${CDV_IOS_SIM:-iPhone 16e}\" -destination-timeout 300 -derivedDataPath \"`mktemp -d 2>/dev/null || mktemp -d -t 'cordova-ios'`\"",
23-
"unit-tests": "jasmine --config=tests/spec/unit.json",
19+
"test": "npm run cover && npm run test:xcode",
20+
"test:unit": "jasmine --config=tests/spec/unit.json",
21+
"test:xcode": "xcodebuild -quiet test -workspace tests/cordova-ios.xcworkspace -scheme CordovaTestApp -destination \"platform=iOS Simulator,name=${CDV_IOS_SIM:-iPhone 16e}\" -destination-timeout 300 -derivedDataPath \"`mktemp -d 2>/dev/null || mktemp -d -t 'cordova-ios'`\"",
22+
"cover": "c8 npm run test:unit",
2423
"lint": "eslint ."
2524
},
2625
"author": "Apache Software Foundation",
Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,15 @@ const path = require('node:path');
2121
const fs = require('node:fs');
2222
const EventEmitter = require('node:events');
2323
const PluginManager = require('cordova-common').PluginManager;
24-
const Api = require('../../../lib/Api');
25-
const check_reqs = require('../../../lib/check_reqs');
24+
const Api = require('../../lib/Api');
25+
const check_reqs = require('../../lib/check_reqs');
26+
const run_mod = require('../../lib/run');
2627

27-
// The lib/run module pulls in simctl, which has a hard requirement that it
28-
// be run on a Mac OS - simply requiring the module is enough to trigger the
29-
// environment checks. These checks will blow up on Windows + Linux.
30-
// So, conditionally pull in the module, and conditionally test the `run`
31-
// method (more below).
32-
let run_mod;
33-
if (process.platform === 'darwin') {
34-
run_mod = require('../../../lib/run');
35-
}
36-
37-
const projectFile = require('../../../lib/projectFile');
38-
const BridgingHeader_mod = require('../../../lib/BridgingHeader.js');
39-
const SwiftPackage_mod = require('../../../lib/SwiftPackage.js');
40-
const Podfile_mod = require('../../../lib/Podfile');
41-
const PodsJson_mod = require('../../../lib/PodsJson');
28+
const projectFile = require('../../lib/projectFile');
29+
const BridgingHeader_mod = require('../../lib/BridgingHeader.js');
30+
const SwiftPackage_mod = require('../../lib/SwiftPackage.js');
31+
const Podfile_mod = require('../../lib/Podfile');
32+
const PodsJson_mod = require('../../lib/PodsJson');
4233
const FIXTURES = path.join(__dirname, 'fixtures');
4334
const iosProjectFixture = path.join(FIXTURES, 'ios-config-xml');
4435

@@ -78,34 +69,29 @@ describe('Platform Api', () => {
7869
});
7970
});
8071

81-
// See the comment at the top of this file, in the list of requires,
82-
// for information on why we conditionall run this test.
83-
// tl;dr run_mod requires the simctl module, which requires mac OS.
84-
if (process.platform === 'darwin') {
85-
describe('run', () => {
86-
beforeEach(() => {
87-
spyOn(check_reqs, 'run').and.returnValue(Promise.resolve());
88-
});
89-
it('should call into lib/run module', () => {
90-
spyOn(run_mod, 'run');
91-
return api.run().then(() => {
92-
expect(run_mod.run).toHaveBeenCalled();
93-
});
72+
describe('run', () => {
73+
beforeEach(() => {
74+
spyOn(check_reqs, 'run').and.returnValue(Promise.resolve());
75+
});
76+
it('should call into lib/run module', () => {
77+
spyOn(run_mod, 'run');
78+
return api.run().then(() => {
79+
expect(run_mod.run).toHaveBeenCalled();
9480
});
9581
});
82+
});
9683

97-
describe('listTargets', () => {
98-
beforeEach(() => {
99-
spyOn(check_reqs, 'run').and.returnValue(Promise.resolve());
100-
});
101-
it('should call into lib/run module', () => {
102-
spyOn(run_mod, 'runListDevices');
103-
return api.listTargets().then(() => {
104-
expect(run_mod.runListDevices).toHaveBeenCalled();
105-
});
84+
describe('listTargets', () => {
85+
beforeEach(() => {
86+
spyOn(check_reqs, 'run').and.returnValue(Promise.resolve());
87+
});
88+
it('should call into lib/run module', () => {
89+
spyOn(run_mod, 'runListDevices');
90+
return api.listTargets().then(() => {
91+
expect(run_mod.runListDevices).toHaveBeenCalled();
10692
});
10793
});
108-
}
94+
});
10995

11096
describe('addPlugin', () => {
11197
const my_plugin = {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
const fs = require('node:fs');
2121
const path = require('node:path');
2222

23-
const BridgingHeader = require(path.resolve(__dirname, '..', '..', '..', 'lib', 'BridgingHeader.js')).BridgingHeader;
23+
const BridgingHeader = require(path.resolve(__dirname, '..', '..', 'lib', 'BridgingHeader.js')).BridgingHeader;
2424
const fixtureBridgingHeader = fs.readFileSync(path.resolve(__dirname, 'fixtures', 'test-Bridging-Header.h'), 'utf-8');
2525

2626
describe('unit tests for BridgingHeader module', () => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const path = require('node:path');
2121
const tmp = require('tmp');
2222
const rewire = require('rewire');
2323

24-
const common = rewire('../../../../lib/plugman/pluginHandlers');
24+
const common = rewire('../../../lib/plugman/pluginHandlers');
2525

2626
tmp.setGracefulCleanup();
2727

tests/spec/unit/Plugman/pluginHandler.spec.js renamed to tests/spec/Plugman/pluginHandler.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ const tmp = require('tmp');
2525
tmp.setGracefulCleanup();
2626

2727
const PluginInfo = require('cordova-common').PluginInfo;
28-
const Api = require('../../../../lib/Api');
29-
const projectFile = require('../../../../lib/projectFile');
30-
const pluginHandlers = require('../../../../lib/plugman/pluginHandlers');
28+
const Api = require('../../../lib/Api');
29+
const projectFile = require('../../../lib/projectFile');
30+
const pluginHandlers = require('../../../lib/plugman/pluginHandlers');
3131

3232
const tempdir = tmp.dirSync({ unsafeCleanup: true });
3333
const temp = path.join(tempdir.name, 'plugman');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const fs = require('node:fs');
2222
const CordovaError = require('cordova-common').CordovaError;
2323

2424
const PROJECT_NAME = 'testProj';
25-
const Podfile = require(path.resolve(__dirname, '..', '..', '..', 'lib', 'Podfile.js')).Podfile;
25+
const Podfile = require(path.resolve(__dirname, '..', '..', 'lib', 'Podfile.js')).Podfile;
2626
const fixturePodfile = path.resolve(__dirname, 'fixtures', PROJECT_NAME, 'platforms', 'ios', 'Podfile');
2727
const fixturePodXcconfigDebug = path.resolve(__dirname, 'fixtures', PROJECT_NAME, 'platforms', 'ios', 'pods-debug.xcconfig');
2828
const fixturePodXcconfigRelease = path.resolve(__dirname, 'fixtures', PROJECT_NAME, 'platforms', 'ios', 'pods-release.xcconfig');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const fs = require('node:fs');
2121
const path = require('node:path');
2222
const CordovaError = require('cordova-common').CordovaError;
2323

24-
const PodsJson = require(path.resolve(__dirname, '..', '..', '..', 'lib', 'PodsJson.js')).PodsJson;
24+
const PodsJson = require(path.resolve(__dirname, '..', '..', 'lib', 'PodsJson.js')).PodsJson;
2525
const fixturePodsJson = path.resolve(__dirname, 'fixtures', 'testProj', 'platforms', 'ios', 'pods.json');
2626

2727
// tests are nested in a describe to ensure clean up happens after all unit tests are run
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
const fs = require('node:fs');
2121
const path = require('node:path');
2222
const tmp = require('tmp');
23-
const SwiftPackage = require('../../../lib/SwiftPackage.js').SwiftPackage;
24-
const Api = require('../../../lib/Api');
23+
const SwiftPackage = require('../../lib/SwiftPackage.js').SwiftPackage;
24+
const Api = require('../../lib/Api');
2525
const EventEmitter = require('node:events').EventEmitter;
2626
const ConfigParser = require('cordova-common').ConfigParser;
2727
const PluginInfo = require('cordova-common').PluginInfo;
28-
const Podfile_mod = require('../../../lib/Podfile');
29-
const PodsJson_mod = require('../../../lib/PodsJson');
28+
const Podfile_mod = require('../../lib/Podfile');
29+
const PodsJson_mod = require('../../lib/PodsJson');
3030

3131
tmp.setGracefulCleanup();
3232

@@ -138,7 +138,7 @@ describe('SwiftPackage', () => {
138138
const content = fs.readFileSync(pkgPath, 'utf8');
139139

140140
// Because we don't have the full project here, it behaves as if linked
141-
const packageLoc = path.dirname(require.resolve('../../../package.json'));
141+
const packageLoc = path.dirname(require.resolve('../../package.json'));
142142
const relativeLink = path.relative(path.dirname(pkgPath), packageLoc).replaceAll(path.sep, path.posix.sep);
143143

144144
expect(content).toContain(`package(name: "cordova-ios", path: "${relativeLink}"`);

0 commit comments

Comments
 (0)