Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Install dependencies
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci
#- run: npm test
- run: npm test
- uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.ADOBE_BOT_NPM_TOKEN }}
Expand Down
16 changes: 16 additions & 0 deletions jest-env/global-teardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/***************************************************************************************
* (c) 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
****************************************************************************************/

module.exports = async () => {
// we're overriding process.cwd in the custom environment. this log is a quick sanity check that it was restored.
console.log('process.cwd after all tests finished:', process.cwd());
};
24 changes: 24 additions & 0 deletions jest-env/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/***************************************************************************************
* (c) 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
****************************************************************************************/

beforeEach(() => {
expect(typeof global.process).toBe('object');
const vmProcessCwd = global.process.cwd();
expect(vmProcessCwd).toBe(process.cwd());

/************** These logs can be used to verify process.cwd() behavior **************/
// this logs process.cwd() from the outer environment (real process)
// console.log('outer process.cwd:', process.cwd());
// but this runs inside the VM environment context
// console.log('inside VM global.process.cwd:', vmProcessCwd);
/************** These logs can be used to verify process.cwd() behavior **************/
});
42 changes: 42 additions & 0 deletions jest-env/override-process-for-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/***************************************************************************************
* (c) 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
****************************************************************************************/

const NodeEnvironmentModule = require('jest-environment-node');
const NodeEnvironment = NodeEnvironmentModule.default || NodeEnvironmentModule;
const path = require('path');

class TestFileCwdEnvironment extends NodeEnvironment {
constructor(config, context) {
super(config, context);
this.testPath = context.testPath;
this.originalCwd = process.cwd;
}


async setup() {
await super.setup();
const testFileDir = path.dirname(this.testPath);

// Override process.cwd for both outer and VM contexts
process.cwd = () => testFileDir;
this.global.process.cwd = () => testFileDir;
}

async teardown() {
// Restore original process.cwd
process.cwd = this.originalCwd;
this.global.process.cwd = this.originalCwd;
await super.teardown();
}
}

module.exports = TestFileCwdEnvironment;
17 changes: 17 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/***************************************************************************************
* (c) 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
****************************************************************************************/

module.exports = {
setupFilesAfterEnv: ['./jest-env/jest.setup.js'],
testEnvironment: './jest-env/override-process-for-tests.js',
globalTeardown: './jest-env/global-teardown.js',
};
Loading