-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix modular add from custom template (#2190)
* Enhanced `modular add` from template logging * Add to Templates documentation * Fix adding from template not adding all files when "files" filter in package.json is not specified * Added template tests * Force addPackage to require.resolve from the modular root * Refactor addPackage tests to not run yarn and use a separate temp testing space * Refactor createModularTestContext to make it more generic * Reduce test template app to skeleton * Use npm-packlist instead of globby for addPackage * Prevent infinite loop in verifyPackageTree
- Loading branch information
1 parent
b438dcc
commit caf75ab
Showing
22 changed files
with
1,391 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
'modular-scripts': patch | ||
--- | ||
|
||
Fixed `modular add` from template not copying all template files when no "files" | ||
field is specified in the package.json - now using npm-packlist for this | ||
Added tests for adding from templates | ||
Refactored addPackage tests to use a temp directory outside the repository and | ||
improve performance by avoiding yarn commands in favour of mocking the behaviour | ||
Added more descriptive log messages when running `modular add` with a local | ||
template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Test File |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "modular-template-app", | ||
"version": "1.1.0", | ||
"exports": { | ||
"./package.json": "./package.json" | ||
}, | ||
"modular": { | ||
"type": "template", | ||
"templateType": "app" | ||
}, | ||
"license": "Apache-2.0", | ||
"files": [ | ||
"src" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as React from 'react'; | ||
import logo from './logo.svg'; | ||
import './App.css'; | ||
|
||
function App(): JSX.Element { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<p> | ||
Edit <code>src/App.tsx</code> and save to reload. | ||
</p> | ||
<a | ||
className="App-link" | ||
href="https://reactjs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn React | ||
</a> | ||
</header> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
9 changes: 9 additions & 0 deletions
9
__fixtures__/templates/modular-template-app/src/__tests__/App.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import App from '../App'; | ||
|
||
test('renders learn react link', () => { | ||
render(<App />); | ||
const linkElement = screen.getByText(/learn react/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Test File |
15 changes: 15 additions & 0 deletions
15
__fixtures__/templates/modular-template-filter/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "modular-template-filter", | ||
"version": "0.0.1", | ||
"exports": { | ||
"./package.json": "./package.json" | ||
}, | ||
"modular": { | ||
"type": "template", | ||
"templateType": "app" | ||
}, | ||
"files": [ | ||
"src" | ||
], | ||
"license": "Apache-2.0" | ||
} |
5 changes: 5 additions & 0 deletions
5
__fixtures__/templates/modular-template-filter/src/__tests__/filter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import add from '../index'; | ||
|
||
test('it should add two numbers', () => { | ||
expect(add(1, 2)).toEqual(3); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function add(a: number, b: number): number { | ||
return a + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Test File |
12 changes: 12 additions & 0 deletions
12
__fixtures__/templates/modular-template-no-filter/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "modular-template-no-filter", | ||
"version": "0.0.1", | ||
"exports": { | ||
"./package.json": "./package.json" | ||
}, | ||
"modular": { | ||
"type": "template", | ||
"templateType": "app" | ||
}, | ||
"license": "Apache-2.0" | ||
} |
3 changes: 3 additions & 0 deletions
3
__fixtures__/templates/modular-template-no-filter/public/robots.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * | ||
Disallow: |
5 changes: 5 additions & 0 deletions
5
__fixtures__/templates/modular-template-no-filter/src/__tests__/no-filter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import add from '../index'; | ||
|
||
test('it should add two numbers', () => { | ||
expect(add(1, 2)).toEqual(3); | ||
}); |
3 changes: 3 additions & 0 deletions
3
__fixtures__/templates/modular-template-no-filter/src/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function add(a: number, b: number): number { | ||
return a + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.