Skip to content

Commit

Permalink
test(jest): add integration test package to test jest config setup
Browse files Browse the repository at this point in the history
with a11y matcher api

Fixes #11
  • Loading branch information
Mohan Raj Rajamanickam committed May 7, 2020
1 parent 36b0087 commit cbbe288
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 15 deletions.
4 changes: 4 additions & 0 deletions jest.config.js
Expand Up @@ -13,4 +13,8 @@ module.exports = {
statements: 80,
},
},
// Exclude integration tests from this config as it has its own config
testPathIgnorePatterns: ['<rootDir>/packages/test-integ'],
// Direct Jest read the jest config file from integration tests
projects: ['<rootDir>', '<rootDir>/packages/test-integ'],
};
4 changes: 0 additions & 4 deletions packages/jest/src/index.ts
Expand Up @@ -7,7 +7,3 @@

export { toBeAccessible } from './matcher';
export { registerA11yMatchers } from './setup';

export const jestConfig = {
setupFilesAfterEnv: [require.resolve('./setup')],
};
3 changes: 0 additions & 3 deletions packages/jest/src/setup.ts
Expand Up @@ -45,6 +45,3 @@ export function adaptA11yConfig(config: A11yConfig): A11yConfig {
},
};
}

// When this file is used as part of Jest setup with setupFilesAfterEnv
registerA11yMatchers();
4 changes: 2 additions & 2 deletions packages/test-integ/__tests__/integration.test.js
Expand Up @@ -6,8 +6,8 @@
*/

describe('integration test @sa11y/jest', () => {
it.skip('should have a11y matchers working with setup in jest.config.js', () => {
// TODO(Fix) : Fails with TypeError: expect(...).toBeAccessible is not a function
it('should have a11y matchers working with setup in jest.config.js', () => {
expect(expect.toBeAccessible).toBeDefined();
expect(document).toBeAccessible();
});
});
13 changes: 13 additions & 0 deletions packages/test-integ/jest-setup.js
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

// Since this is not a typescript project, disabling typescript eslint warning
// TODO (lint): using 'exclude: ["./packages/test-integ/**/*.js"]' in tsconfig.eslint.json doesn't work
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { registerA11yMatchers } = require('@sa11y/jest');

registerA11yMatchers();
5 changes: 1 addition & 4 deletions packages/test-integ/jest.config.js
Expand Up @@ -5,9 +5,6 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { jestConfig } = require('@sa11y/jest');

module.exports = {
...jestConfig,
setupFilesAfterEnv: ['./jest-setup.js'],
};
2 changes: 1 addition & 1 deletion tsconfig.common.json
Expand Up @@ -8,7 +8,7 @@
"strict": true,
"noEmitOnError": true,
"noUnusedLocals": true,
"module": "ESNext",
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
@@ -1,4 +1,4 @@
{
"compilerOptions": { "strict": true },
"include": ["*.js", "./packages/**/*.ts", "./packages/**/*.js"]
"include": ["*.js", "./packages/**/*.ts", "./packages/test-integ/**/*.js"]
}

0 comments on commit cbbe288

Please sign in to comment.