Skip to content

Commit 6450f43

Browse files
committed
Lint blueprint output and add tests that confirm this
1 parent d5c62a7 commit 6450f43

7 files changed

Lines changed: 89 additions & 41 deletions

File tree

files/app/config/environment.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,30 @@ import { assert } from '@ember/debug';
33

44
const config = loadConfigFromMeta('<%= name %>') as unknown;
55

6-
assert("config is not an object", typeof config === "object" && config !== null);
7-
assert("modulePrefix was not detected on your config", "modulePrefix" in config && typeof config.modulePrefix === 'string')
8-
assert("locationType was not detected on your config", "locationType" in config && typeof config.locationType === 'string')
9-
assert("rootURL was not detected on your config", "rootURL" in config && typeof config.rootURL === 'string')
10-
assert("APP was not detected on your config", "APP" in config && typeof config.APP === 'object')
6+
assert(
7+
'config is not an object',
8+
typeof config === 'object' && config !== null
9+
);
10+
assert(
11+
'modulePrefix was not detected on your config',
12+
'modulePrefix' in config && typeof config.modulePrefix === 'string'
13+
);
14+
assert(
15+
'locationType was not detected on your config',
16+
'locationType' in config && typeof config.locationType === 'string'
17+
);
18+
assert(
19+
'rootURL was not detected on your config',
20+
'rootURL' in config && typeof config.rootURL === 'string'
21+
);
22+
assert(
23+
'APP was not detected on your config',
24+
'APP' in config && typeof config.APP === 'object'
25+
);
1126

1227
export default config as {
13-
modulePrefix: string,
14-
locationType: string,
15-
rootURL: string,
16-
APP: Record<string, unknown>
28+
modulePrefix: string;
29+
locationType: string;
30+
rootURL: string;
31+
APP: Record<string, unknown>;
1732
} & Record<string, unknown>;

files/app/templates/_js_application.gjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { pageTitle } from 'ember-page-title';
22
<% if (welcome) {%>import { WelcomePage } from 'ember-welcome-page';<% } %>
33

44
<template>
5-
{{pageTitle "<%= namespace %>"}}
6-
<% if (welcome) { %>
5+
{{pageTitle "<%= namespace %>"}}<% if (welcome) { %>
6+
77
{{outlet}}
88

99
{{! The following component displays Ember's default welcome message. }}

files/app/templates/_ts_application.gts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { pageTitle } from 'ember-page-title';
22
<% if (welcome) {%>import { WelcomePage } from 'ember-welcome-page';<% } %>
33

44
<template>
5-
{{pageTitle "<%= namespace %>"}}
6-
<% if (welcome) { %>
5+
{{pageTitle "<%= namespace %>"}}<% if (welcome) { %>
6+
77
{{outlet}}
88

99
{{! The following component displays Ember's default welcome message. }}

files/tsconfig.json

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
{
22
"extends": "@ember/app-tsconfig",
3-
"include": [
4-
"app", "tests", "types"
5-
],
3+
"include": ["app", "tests", "types"],
64
"glint": {
7-
"environment": [
8-
"ember-loose",
9-
"ember-template-imports"
10-
]
5+
"environment": ["ember-loose", "ember-template-imports"]
116
},
127
"compilerOptions": {
138
"allowJs": true,
149
"paths": {
15-
"<%= name %>/tests/*": [
16-
"./tests/*"
17-
],
18-
"<%= name %>/*": [
19-
"./app/*"
20-
],
21-
"*": [
22-
"./types/*"
23-
]
10+
"<%= name %>/tests/*": ["./tests/*"],
11+
"<%= name %>/*": ["./app/*"],
12+
"*": ["./types/*"]
2413
},
25-
"types": [
26-
"ember-source/types",
27-
"@embroider/core/virtual",
28-
"vite/client"
29-
]
30-
},
14+
"types": ["ember-source/types", "@embroider/core/virtual", "vite/client"]
15+
}
3116
}

tests/default.test.mjs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ describe('basic functionality', function () {
5252
);
5353
});
5454

55-
it('successfully lints', async function () {
56-
let result = await project.execa('pnpm', ['lint']);
57-
58-
console.log(result.stdout);
59-
});
60-
6155
it('successfully builds', async function () {
6256
let result = await project.execa('pnpm', ['build']);
6357

tests/helpers.mjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,33 @@ export const emberCli = findEmber();
1919

2020
const appName = 'test-app';
2121

22+
export function newProject({
23+
name = appName,
24+
flags = [],
25+
} = {}) {
26+
let dir;
27+
28+
beforeAll(async () => {
29+
const tmpDir = (await tmp.dir()).path;
30+
dir = join(tmpDir, name);
31+
await execa({
32+
cwd: tmpDir,
33+
})`${localEmberCli} new ${name} -b ${blueprintPath} --skip-git --pnpm ${flags}`;
34+
});
35+
36+
return {
37+
appName: () => name,
38+
dir: () => dir,
39+
$: (...args) => execa({ cwd: dir })(...args),
40+
execa: (program, args, options = {}) => {
41+
return execa(program, args, {
42+
cwd: dir,
43+
...options,
44+
});
45+
},
46+
};
47+
};
48+
2249
export function newProjectWithFixtures({
2350
flags = [],
2451
fixturePath,

tests/lint.test.mjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, it, expect } from 'vitest';
2+
3+
import { newProject } from './helpers.mjs';
4+
5+
describe('linting & formatting', function () {
6+
describe('JavaScript', function () {
7+
let project = newProject();
8+
9+
it('yields output for JavaScript without errors', async function () {
10+
let { exitCode } = await project.execa('pnpm', ['lint']);
11+
12+
expect(exitCode).to.equal(0);
13+
});
14+
});
15+
16+
describe('TypeScript', function () {
17+
let project = newProject({
18+
flags: ['--typescript']
19+
});
20+
21+
it('yields output for JavaScript without errors', async function () {
22+
let { exitCode } = await project.execa('pnpm', ['lint']);
23+
24+
expect(exitCode).to.equal(0);
25+
});
26+
});
27+
});

0 commit comments

Comments
 (0)