Skip to content

Commit 18f6f11

Browse files
authored
add tests (#142)
* copy test dirs * add tests * do tests * fix lint * fix lock * pnpm * pnpm * latest * Update ci.yml * fix test * run all tests * fix * use codeframe formatter
1 parent f9b43ea commit 18f6f11

Some content is hidden

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

54 files changed

+5311
-7580
lines changed

.eslintrc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
'ecmaVersion': 'latest',
44
sourceType: 'module',
55
},
6-
plugins: ['node', 'jest'],
6+
plugins: ['n', 'jest'],
77
'env': {
88
'browser': true,
99
'commonjs': true,
@@ -12,11 +12,11 @@ module.exports = {
1212
'extends': [
1313
'eslint:recommended',
1414
'plugin:jest/recommended',
15-
'plugin:node/recommended',
15+
'plugin:n/recommended',
1616
],
1717
'rules': {
18-
'node/no-unpublished-require': 'off',
19-
'node/no-unsupported-features/es-syntax': 'off',
18+
'n/no-unpublished-require': 'off',
19+
'n/no-unsupported-features/es-syntax': 'off',
2020
'indent': [
2121
'error',
2222
2

.github/workflows/ci.yml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,28 @@ jobs:
2121

2222
steps:
2323
- uses: actions/checkout@v4
24-
24+
- uses: pnpm/action-setup@v4
25+
with:
26+
version: 'latest'
2527
- name: Use Node.js ${{ matrix.node-version }}
2628
uses: actions/setup-node@v4
2729
with:
2830
node-version: ${{ matrix.node-version }}
29-
cache: 'npm'
31+
cache: 'pnpm'
32+
33+
- run: pnpm install
3034

31-
- run: npm install
35+
- run: pnpm run lint:js
3236

33-
- run: npm run lint:js
37+
- run: pnpm run test --runInBand
3438

35-
- run: npm run test -- --runInBand
39+
- run: pnpm --filter '*' test
3640

3741
deploy:
3842
permissions:
3943
contents: write
4044
deployments: write
41-
45+
4246
needs: [ test ]
4347
if: github.ref == 'refs/heads/main'
4448
runs-on: ubuntu-latest
@@ -49,23 +53,26 @@ jobs:
4953
- uses: actions/checkout@v4
5054
with:
5155
token: ${{ secrets.GITHUB_TOKEN }}
56+
- uses: pnpm/action-setup@v4
57+
with:
58+
version: 'latest'
5259
- name: Use Node.js
5360
uses: actions/setup-node@v4
5461
with:
5562
node-version: 16.x
56-
- name: npm install, build,
63+
- name: pnpm install, build,
5764
run: |
5865
mkdir ~/.ssh
5966
ssh-keyscan github.com >> ~/.ssh/known_hosts
60-
npm install --no-audit --legacy-peer-deps
67+
pnpm install --no-audit --legacy-peer-deps
6168
version=$(cat package.json | jq -r '.version')
6269
git fetch --unshallow
6370
git fetch --all --tags
6471
TAG=v$version
6572
env:
6673
CI: true
6774
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
68-
- name: deploy npm
75+
- name: deploy pnpm
6976
if: github.ref == 'refs/heads/main'
7077
run: |
7178
version=$(cat package.json | jq -r '.version')
@@ -74,7 +81,7 @@ jobs:
7481
echo "tag exists";
7582
else
7683
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
77-
npm publish || echo "already published"
84+
pnpm publish || echo "already published"
7885
fi
7986
env:
8087
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
@@ -91,7 +98,7 @@ jobs:
9198
if git rev-parse "$TAG" >/dev/null 2>&1; then
9299
echo "tag exists";
93100
else
94-
npm i -g lerna-changelog
101+
pnpm i -g lerna-changelog
95102
export GITHUB_AUTH=$GITHUB_TOKEN
96103
export changelog=$(lerna-changelog --next-version=$version)
97104
echo -e "# Changelog\n\n$changelog\n$(tail --lines=+2 CHANGELOG.md)" > CHANGELOG.md

.npmrc

Whitespace-only changes.

lib/config-legacy/base.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
root: true,
3+
4+
plugins: ['ember-template-lint'],
5+
6+
rules: {}
7+
};

lib/config-legacy/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const info = require('../ember-template-lint/info');
2+
const base = require('./base');
3+
4+
const configs = {};
5+
6+
Object.entries(info.configs).forEach(([name, config]) => {
7+
Object.entries(config.rules).forEach(([name, conf]) => {
8+
if (typeof conf == 'boolean') {
9+
config.rules[name] = [conf ? 'error' : 'off'];
10+
}
11+
});
12+
configs[name] = {...base, rules: config.rules};
13+
});
14+
configs['config'] = {
15+
...base,
16+
rules: info.configuredRules,
17+
overrides: info.configuredOverrides,
18+
};
19+
20+
module.exports = configs;
21+

lib/config/base.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
module.exports = {
22
root: true,
33

4-
plugins: ['ember-template-lint'],
4+
plugins: {
5+
'ember-template-lint': require('../index'),
6+
},
57

6-
rules: {},
7-
8-
overrides: [
9-
{
10-
files: ['**/*.hbs'],
11-
parser: require.resolve('../parser/hbs-parser'),
12-
processor: 'ember-template-lint/noop'
13-
},
14-
{
15-
files: ['**/*.gts', '**/*.gjs'],
16-
parser: 'ember-eslint-parser',
17-
processor: 'ember-template-lint/noop'
18-
},
19-
],
8+
rules: {}
209
};

lib/config/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Object.entries(info.configs).forEach(([name, config]) => {
1313
});
1414
configs['config'] = {
1515
...base,
16-
rules: info.configuredRules
16+
rules: info.configuredRules,
17+
overrides: info.configuredOverrides,
1718
};
1819

1920
module.exports = configs;

lib/ember-template-lint/config.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
const templateLintConfig = {
22
rules: {},
33
plugins: [],
4+
overrides: [],
45
};
56

7+
let current = templateLintConfig;
8+
69
function registerRule(name, config) {
7-
templateLintConfig.rules[name] = Array.isArray(config) ? config[0] : config;
10+
current.rules[name] = Array.isArray(config) ? config[0] : config;
811
}
912

1013
function registerPlugin(name) {
11-
templateLintConfig.plugins.push(name);
14+
current.plugins.push(name);
15+
}
16+
17+
function startOverride(files) {
18+
current = {
19+
files,
20+
rules: {}
21+
};
22+
templateLintConfig.overrides.push(current);
23+
}
24+
25+
function finishOverride() {
26+
current = templateLintConfig;
1227
}
1328

1429
module.exports = {
1530
registerRule,
1631
registerPlugin,
32+
startOverride,
33+
finishOverride,
1734
templateLintConfig
18-
};
35+
};

lib/ember-template-lint/info.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,34 @@ Object.values(configs).forEach((config) => {
9393

9494
const configuredRules = {};
9595
Object.entries(lintConfigs.configuredRules).forEach(([name, conf]) => {
96-
if (conf.severity) {
96+
configuredRules['ember-template-lint/' + name] = configuredRules['ember-template-lint/' + name] || [];
97+
configuredRules['ember-template-lint/' + name].push(conf.severity);
98+
if (typeof conf.config !== 'boolean') {
99+
configuredRules['ember-template-lint/' + name].push(conf.config);
100+
}
101+
});
102+
103+
const configuredOverrides = [];
104+
105+
for (const configuredOverride of lintConfigs.configuredOverrides) {
106+
const configuredRules = {};
107+
Object.entries(configuredOverride.rules).forEach(([name, conf]) => {
97108
configuredRules['ember-template-lint/' + name] = configuredRules['ember-template-lint/' + name] || [];
98109
configuredRules['ember-template-lint/' + name].push(conf.severity);
99110
if (typeof conf.config !== 'boolean') {
100111
configuredRules['ember-template-lint/' + name].push(conf.config);
101112
}
102-
}
103-
});
113+
});
114+
configuredOverrides.push({
115+
files: configuredOverride.files,
116+
rules: configuredRules
117+
});
118+
}
119+
104120

105121
module.exports = {
106122
configs: configs,
107123
rules: createRules(rules),
108-
configuredRules: configuredRules
124+
configuredRules,
125+
configuredOverrides
109126
};

lib/ember-template-lint/worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ runAsWorker(async (options) => {
88
configs: lint.config.loadedConfigurations,
99
rules: Object.keys(lint.config.loadedRules),
1010
configuredRules: lint.config.rules,
11+
configuredOverrides: lint.config.overrides,
1112
};
1213
});

0 commit comments

Comments
 (0)